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