c# - Can two repositories share the same unit of work? -
in project have 2 tabs , in viewmanager
class have following code add register views region ,
ibondsunitofwork unitofwork = new bondsunitofwork(new testentities(dalutilities.projconnectionstring)); irepo1 repo = new repo1(unitofwork); irepo2 repo_second = new repo2(unitofwork);
my question can use same unitofwork
different repositories ?
yes, there no restriction doing it. getting control of data access in level above, when access repositories , tasks insert
, update
, delete
. pseudo-code sample, sample:
ibondsunitofwork unitofwork = new bondsunitofwork(new testentities(dalutilities.projconnectionstring)); try { unitofwork.open(); unitofwork.begintransaction(); irepo1 repo = new repo1(unitofwork); repo.update(obj); irepo2 repo_second = new repo2(unitofwork); repo.add(obj2); unitofwork.commit(); } catch (exception ex) { unitofwork.rollback(); // catch exception here... // log.. } { unitofwork.close(); }
Comments
Post a Comment