2
ninjectKernel.Bind<IReleaseDataProvider>().To<ReleaseDataProvider>().WithConstructorArgument("connectionString", _connectionString);    

ninjectKernel.Bind<IReleaseService>().To<ReleaseService>().WithConstructorArgument("releaseDataProvider", releaseDataProvider);

如何获取应该在 releaseService 类的构造函数中传递的 releaseDataProvider 实例?

4

1 回答 1

3
ninjectKernel.Bind<IReleaseDataProvider>().To<ReleaseDataProvider>().WithConstructorArgument("connectionString", _connectionString); 

ninjectKernel.Bind<IReleaseService>().To<ReleaseService>();

No need to pass/get the releaseDataProvider manually.

When the ReleaseService instance is created its constructor parameter instance (ReleaseDataProvider) and those dependencies(connectionString) will be resolved

于 2012-06-15T21:17:03.390 回答