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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -