c# - Is it bad design to have access to the UnitOfWork in the Repository? -
background: entity framework4.1 , mvc4
my setup has model entities, , generic repository , model specific repositories userrepository, productrepository inherit generic repository.
i have service layer use these repositories along business logic, , unitofwork object accessible here call commit.
with unit of work pattern, , quesiton is:
is poor design let repository layer have access unitofwork object?
to me seems 'leak' because things may commit when don't realize it.
is correct?
e.g.
public class productservice { public void saveproduct(product product) { try { productrepository.save(product); statsrepository.update(product); this.unitofwork.commit(); } catch(..) { // } finally() { // } } }
now if 1 of calls fails, commit won't called.
but if in abcrepository layer had access uofw object , called commit, behave in inconsistant manner.
i think right way of implementing repository , unitofwork
http://code.cmsstores.com/implementing-unit-of-work-pattern-dot-net/
Comments
Post a Comment