c# - Unit of Work and Repository Pattern -


i implement simple igenericrepository , iunitofwork interfaces in application i'm not sure whats best way it.

as far understand, unitofwork should used writing, while repository should used reading. have encountered 1 architecture , it, found interfaces , not implementations, , i'm not sure how should implement those.

public interface igenericrepository : idisposable {     iunitofwork createunitofwork();     t firstordefault<t>(expression<func<t, bool>> predicate) t : class, ibaseentity;     iqueryable<t> get<t>(expression<func<t, bool>> predicate = null, func<iqueryable<t>, iorderedqueryable<t>> sorter = null, params string[] includeproperties) t : class, ibaseentity;     iqueryable<t> getall<t>() t : class, ibaseentity;     idbcontext getdbcontext(); }  public interface iunitofwork : idisposable {     int commit();     bool delete<t>(t entity) t : class, ibaseentity;     int deleteitems<t>(ilist<t> entities) t : class, ibaseentity;     bool insert<t>(t entity) t : class, ibaseentity;     int insertitems<t>(ilist<t> entities) t : class, ibaseentity;     bool update<t>(t entity) t : class, ibaseentity;     int updateitems<t>(ilist<t> entities) t : class, ibaseentity; } 

i'm not sure how should work. should use idbcontextfactory within repository share dbcontext between repository , unitofwork or should have separate dbcontexts? if implement unitofwork write , repository read, should there unitofworks dbcontext write , repositorys dbcontext read or should share same dbcontext?

i appreciate explanation of how dbcontext , unitofwork/repository should work.

those implemented in service in such way:

public customerservice(igenericrepository repository) {     this.repository = repository;     this.context = this.repository.getdbcontext(); }  public void updatecustomer(customer customer) {     var uow = this.repository.createunitofwork();     uow.addforsave(customer);     uow.commit(); }  public list<customer> getall() {     return this.repository.getall<customer>(); } 

any help, explanation dbcontext , uow/repository relation, or tutorial similar implementation help.

regards.

i think this need. tags in 1 article )


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -