i'm using entity framework 5.0 , mvc4. have couple of domains. each of them has own dbcontext (which uses appropriate tables), repository , service. implemented unitofwork.
handling specific flow in transaction inside 1 service specific domain simple. i'm doing operations on tables , @ end i'm invoking unitofwork.save, behaves transaction.commit.
but lets assume have case in have invoke operations 2 different domains , 2 operations must put inside 1 transaction. have access services domains controller actions invoked there. @ moment can see 3 solutions:
- i must have unitofwork in controller , call save method @ end (i don't idea).
- create service in have unitofwork , access both services (actually same solution above, i'm moving logic separate class)
- i have create additional transactionscope inside controller , commit @ end
please let me know option think best. if have other 3 above, let me know. or maybe wrong concept? mean domains , db contexts?
assuming unitofwork implementation supports normal transactions in .net, can following , should enroll in running transaction.
protected transactionscope createtransactionscope() { var options = new transactionoptions(); options.isolationlevel = isolationlevel.readcommitted; options.timeout = transactionmanager.maximumtimeout; return new transactionscope(transactionscopeoption.required, options); } using (var scope = this.createtransactionscope()) { // operations context 1 // operations context 2 scope.complete(); }
Comments
Post a Comment