c# - Mixing Repository implementations for different data sources -


a repository defined martin fowler supposed act in-memory domain object collection. allows application (in theory) ignorant of persistence mechanism.

so under normal circumstances you'd have this:

public void mybusinesslogicmethod () {     ...     irepository<customer> repository = myioccontainer.resolve<irepository<customer>>();     repository.add(customer); } 

if have series of inserts/updates wish , want mechanism roll should of them fail you'd need sort of unitofwork implementation:

public void mybusinesslogicmethod () {     ...     using (iunitofwork uow = new unitofwork()){         irepository<customer> customerrepo = myioccontainer.resolve<irepository<customer>>(uow);         customerrepo.add(customer);           irepository<order> orderrepo = myioccontainer.resolve<irepository<order>>(uow);         orderrepo.add(order);           irepository<invoice> invoicerepo = myioccontainer.resolve<irepository<invoice>>(uow);         invoicerepo.update(invoice);          uow.save();      } } 

however if had bizarre requirement customer repository acting against sqlserver database, order repository against mysql database , invoice repository against postgresql database, how go handling transactions each database session?

now bit of contrived example sure every repository implementation i've come across seems know @ level it's particular database , orm being used.

imagine scenario have 2 repositories 1 going database , other calling web service. whole point of repositories application shouldn't care data source going without jumping through massive hoops don't see how these scenarios can accounted without application knowing @ level "fyi going data source x we'd better treat differently".

is there pattern or implementation addresses issue? seems me if using database x , orm y entire application repositories work splendidly, if due technical debt course deviates benefits of repositories reduced.

in unitofwork, suggested, should use transactionscope transaction. elevates, in case, msdtc , ensure enlisted operations correctly executed before commit or otherwise rollback.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -