ninjectKernel.Bind<IReleaseDataProvider>().To<ReleaseDataProvider>().WithConstructorArgument("connectionString", _connectionString);
ninjectKernel.Bind<IReleaseService>().To<ReleaseService>().WithConstructorArgument("releaseDataProvider", releaseDataProvider);
如何获取应该在releaseService类的构造函数中传递的releaseDataProvider实例?
答案 0 :(得分:3)
ninjectKernel.Bind<IReleaseDataProvider>().To<ReleaseDataProvider>().WithConstructorArgument("connectionString", _connectionString);
ninjectKernel.Bind<IReleaseService>().To<ReleaseService>();
无需手动传递/获取releaseDataProvider。
创建ReleaseService实例时,将解析其构造函数参数实例(ReleaseDataProvider)和那些依赖项(connectionString)