title: How Use DependencyInjection in GenericRepository and UnitOfWork
body: <p>I have a WindowsForm Project With this design :<br>
  DAL(GenericRepository  => UnitOfWork)    =>  BLL(Service)   =>   UI<br>
  And use EntityFramWork, Interface, GenericRepository, Dependency Injection</p>
  
  <p>My Code in Repository(DAL) :</p>
  
  <pre><code>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();  
         } 
  } 
  </code></pre>
  
  <p>UnitOfWork(DAL) : </p>
  
  <pre><code>public class UnitOfWork : RepositoryBase, IUnitOfWork, IDisposable  
     {  
         private Dictionaryobject&gt; repositories;  
         private bool disposed = false;  
  
         public UnitOfWork(GlobalERPEntities dbContext)  
         {  
             DBContext = dbContext;  
         }  
  
         public IRepository Repository() where T : class  
         {  
             if (repositories == null)  
             {  
                 repositories = new Dictionaryobject&gt;();  
             }  
  
             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;  
         } 
  </code></pre>
  
  <p>Service(BLL) :</p>
  
  <pre><code>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();  
         } 
  </code></pre>
  
  <p>MyForm(UI) :</p>
  
  <pre><code>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);  
                     }  
                 }  
  </code></pre>
  
  <p>Iknow should not use DAL Layer in UI layer and BLL is between DAL and UI
  but i have error in ui</p>
  
  <pre><code>using (Service_HR_Person srvPerson = new Service_HR_Person())
  </code></pre>
  
  <p>"new Service_HR_Person()" say need an arguman in () that is unitofwork but we should not use unitofwork in UI<br></p>
  
  <p>i read some article and sample that use IOC , ninject ,bootstraper and ... but i cant write true code<br>
  How To use Ninject or IOC?<br>
  please help me with code<br>
  thankyou</p>