我的一个服务层(ProductService)有4个参数化构造函数。 并且所有4个构造函数都注入了不同的存储库类型。
public class ProductService : IProductService
{
private IUserDal<Users> mUserDal { get; set; }
private IItemDal<Item> mItemDal { get; set; }
private IRoleDal<Role> mRoleDal { get; set; }
private IBranchDal<Branch> mBranchDal { get; set; }
public ProductService (IUserDal<Users> userDal)
{
mUserDal = userDal;
}
public ProductService (IItemDal<Item> itemDal)
{
mItemDal = itemDal;
}
public ProductService (IRoleDal<Role> roleDal)
{
mRoleDal = roleDal;
}
public ProductService (IBranchDal<Branch> branchDal)
{
mBranchDal = branchDal;
}
}
ProductService 层用于某些Controller类。
我正在将此ProductService类注册到Bootstrapper.cs(Unity DI)文件及其所有依赖项类型。但它没有正确注册。下面的一些示例如下: -
类型1:
container.RegisterType<IUserDal<Users>, UserDal>();
container.RegisterType<IItemDal<Item>,ItemDal>();
container.RegisterType<IRoleDal<Role>,RoleDal>();
container.RegisterType<IBranchDal<Branch>,BranchDal>();
container.RegisterType<IProductService,ProductService>();
类型2:
container.RegisterType<IProductService, ProductService>(new InjectionConstructor(typeof(IUserDal<Users>), typeof(IItemDal<Item>), typeof(IRoleDal<Role>), typeof(IBranchDal<Branch>)));
但是上述类型都没有工作。任何人都知道如何在Bootstrapper文件中注册任何具有多种存储库类型的服务类?