【发布时间】:2023-03-04 09:02:01
【问题描述】:
所以我正在研究 API 并将 Ninject 用于 DI 和 IoC。我知道基本代码是如何使用 Ninject 工作的,但是在其中一个类的构造函数中,正在发送 Logger 的对象。我不想在构造函数设计项中发送它,而是在NinjectWebCommon.cs 文件中传递它。
public GAMonthlyAPIController() : this(new GAMonthlySQLReader(new NullLogger()))
这是构造函数。
kernel.Bind<IGAMonthlyReader>().To<GAMonthlySQLReader>();
这是NinjectWebCommon.cs 中的条目我想将它绑定到NinjectWebCommon.cs 而不是默认值。我怎么能通过呢?我什至不知道要搜索什么,所以我可以找到答案。
【问题讨论】:
标签: c# dependency-injection inversion-of-control ninject ninject.web.mvc