获取ninject的具体实例

时间:2012-06-15 19:47:43

标签: c# dependency-injection ninject

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

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

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

1 个答案:

答案 0 :(得分:3)

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

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

无需手动传递/获取releaseDataProvider。

创建ReleaseService实例时,将解析其构造函数参数实例(ReleaseDataProvider)和那些依赖项(connectionString)