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 classwhere T : - {
- 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 Dictionary
object> repositories; - private bool disposed = false;
- public UnitOfWork(GlobalERPEntities dbContext)
- {
- DBContext = dbContext;
- }
- public IRepository
Repository class() where T : - {
- if (repositories == null)
- {
- repositories = new Dictionary
object>(); - }
- 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);
- }
- }
but i have error in ui
- using (Service_HR_Person SrvPerson = new Service_HR_Person())
please help me with code
thankyou
XxxsenatorxxxPosted Jan 16, 2019, 3:13 AM
Sai Kumar KoonaPosted Jan 16, 2019, 12:06 AM