Xxxsenatorxxx

Xxxsenatorxxx

  • 1.5k
  • 92
  • 698

How to use service(BLL) in Form(windowsForm) With DI

Jan 15 2019 2:30 AM
I have a WindowsForm Project With this design :
 DAL(GenericRepository  => UnitOfWork)    =>  BLL(Service)   =>   UI
And EntityFramWork, Interface, GenericRepository, Dependency Injection
 
My Code in Repository(DAL) :
  1. public class Repository : RepositoryBase, IDisposable, IRepository where T : class  
  2.    {  
  3.        private readonly DbSet dbSet;  
  4.        private bool disposed = false;  
  5.   
  6.        public Repository(GlobalERPEntities dbContext)  
  7.        {  
  8.            DBContext = dbContext;  
  9.            dbSet = DBContext.Set();  
  10.        }  
  11.   
  12.        public virtual IEnumerable GetAll()  
  13.        {  
  14.            return dbSet.ToList();  
  15.        } 
UnitOfWork(DAL) :
  1. public class UnitOfWork : RepositoryBase, IUnitOfWork, IDisposable  
  2.    {  
  3.        private Dictionaryobject> repositories;  
  4.        private bool disposed = false;  
  5.              
  6.        public UnitOfWork(GlobalERPEntities dbContext)  
  7.        {  
  8.            DBContext = dbContext;  
  9.        }  
  10.   
  11.        public IRepository Repository() where T : class  
  12.        {  
  13.            if (repositories == null)  
  14.            {  
  15.                repositories = new Dictionaryobject>();  
  16.            }  
  17.   
  18.            if (repositories.Keys.Contains(typeof(T)) == true)  
  19.            {  
  20.                return repositories[typeof(T)] as Repository;  
  21.            }  
  22.            Repository repo = new Repository(DBContext);  
  23.            repositories.Add(typeof(T), repo);  
  24.            return repo;  
  25.        } 
 Service(BLL) :
  1. public class Service_HR_Person : IService_HR_Person ,  IDisposable  
  2.    {  
  3.        private readonly IUnitOfWork UnitOfWork;  
  4.   
  5.        public Service_HR_Person(IUnitOfWork unitOfWork)  
  6.        {  
  7.            UnitOfWork = unitOfWork;  
  8.        }  
  9.   
  10.        public virtual IEnumerable GetAll()  
  11.        {  
  12.            return UnitOfWork.Repository().GetAll().ToList();  
  13.        } 
 MyForm(UI) :
  1. using (Service_HR_Person SrvPerson = new Service_HR_Person())  
  2.                {  
  3.                    SrvPerson.Delete(base.rowid);  
  4.                    try  
  5.                    {  
  6.                        SrvPerson.Save();
  7.                        MessageManager.Show(Enums.MessageBoxType.InformationTransactionSuccessfully);  
  8.                    }  
  9.                    catch (Exception ex)  
  10.                    {  
  11.                        MessageManager.Show(ErrorManager.ProccessException(ex), Enums.MessageBoxType.Error);  
  12.                    }  
  13.                } 
 Iknow should not use DAL Layer in UI layer and BLL is between DAL and UI
but i have error in ui
  1. using (Service_HR_Person SrvPerson = new Service_HR_Person())   
 Service_HR_Person say need an arguman in () that is unitofwork but we should not use unitofwork in UI
 
please help me with code
thankyou

Answers (2)