我正在尝试在我的解决方案中保留一个ninject load()方法并尝试使用基于约定的绑定。下面是我的类层次结构。 AccountTypes和PaymentTypes是同一项目中的单独名称空间。它们都是公共类和接口。
AccountTypes
IAccountTypes
AccountTypeA
AccountTypeB
PaymentTypes
IPaymentTypes
PaymentTypeA
PaymentTypeB
我有一个类,我已经覆盖了ninject Load()方法,如下所示。
public class NinjectLoader : NinjectModule
{
public override void Load()
{
Kernel.Bind(x => x
.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom<IAccountTypes>()
.BindAllInterfaces());
Kernel.Bind(x => x
.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom<IPaymentTypes>()
.BindAllInterfaces());
}
}
当运行load()方法并且调用下面的构造函数时,accountTypes仍为空。
private readonly IEnumerable<IAccountTypes> _accountTypes;
public OtherDeliveryMethodWorkflow(IEnumerable<IAccountTypes> accountTypes)
{
_accountTypes = accountTypes;
}
我已经使用了ninject绑定,但是我需要通过约定来实现这一点,因为我的代码会随着时间的推移而扩展,并且将每个类绑定到接口都不是一个好的解决方案。