There are 4 parameterized constructor of one of my service layer(ProductService). And all of the 4 constructors are injected with different repository types.
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;
}
}
And ProductService layer is use in some of the Controller classes.
I am registering this ProductService class to Bootstrapper.cs(Unity DI) file with all of its dependencies types.But it's not registering properly.Some of the examples are below :-
Type 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>();
Type 2:
container.RegisterType<IProductService, ProductService>(new InjectionConstructor(typeof(IUserDal<Users>), typeof(IItemDal<Item>), typeof(IRoleDal<Role>), typeof(IBranchDal<Branch>)));
But none of the above types are working.Can anyone know how to register any service class with multiple repository types in Bootstrapper file ?