gpt4 book ai didi

c# - 获取ninject的具体实例

转载 作者:行者123 更新时间:2023-11-30 22:27:56 25 4
gpt4 key购买 nike

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) 将被解析

关于c# - 获取ninject的具体实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11057252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com