How to register service class with multiple repository types in Bootstrapper file?

佐手、 提交于 2019-12-02 15:38:07

问题


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 ?

来源:https://stackoverflow.com/questions/23443921/how-to-register-service-class-with-multiple-repository-types-in-bootstrapper-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!