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) :
- public class Repository : RepositoryBase, IDisposable, IRepository where T : class
- {
- private readonly DbSet dbSet;
- private bool disposed = false;
-
- public Repository(GlobalERPEntities dbContext)
- {
- DBContext = dbContext;
- dbSet = DBContext.Set();
- }
-
- public virtual IEnumerable GetAll()
- {
- return dbSet.ToList();
- }
UnitOfWork(DAL) :
- public class UnitOfWork : RepositoryBase, IUnitOfWork, IDisposable
- {
- private Dictionaryobject> repositories;
- private bool disposed = false;
-
- public UnitOfWork(GlobalERPEntities dbContext)
- {
- DBContext = dbContext;
- }
-
- public IRepository Repository() where T : class
- {
- if (repositories == null)
- {
- repositories = new Dictionaryobject>();
- }
-
- if (repositories.Keys.Contains(typeof(T)) == true)
- {
- return repositories[typeof(T)] as Repository;
- }
- Repository repo = new Repository(DBContext);
- repositories.Add(typeof(T), repo);
- return repo;
- }
Service(BLL) :
- public class Service_HR_Person : IService_HR_Person , IDisposable
- {
- private readonly IUnitOfWork UnitOfWork;
-
- public Service_HR_Person(IUnitOfWork unitOfWork)
- {
- UnitOfWork = unitOfWork;
- }
-
- public virtual IEnumerable GetAll()
- {
- return UnitOfWork.Repository().GetAll().ToList();
- }
MyForm(UI) :
- using (Service_HR_Person SrvPerson = new Service_HR_Person())
- {
- SrvPerson.Delete(base.rowid);
- try
- {
- SrvPerson.Save();
- MessageManager.Show(Enums.MessageBoxType.InformationTransactionSuccessfully);
- }
- catch (Exception ex)
- {
- MessageManager.Show(ErrorManager.ProccessException(ex), Enums.MessageBoxType.Error);
- }
- }
Iknow should not use DAL Layer in UI layer and BLL is between DAL and UI
but i have error in ui
- 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