entity framework - EF6 DbContext lifecycle issue -
i've decided architect solution without repositories , unit of work (given ef repository/uow why abstract abstraction). have service/business logic layer phone call ef directly. service has number of methods (create, update, delete) phone call _context.savechanges() , injecting dbcontext in constructor.
however if phone call multiple methods using same service instance , 1 fails, farther service methods fail. example
var svc = new personservice(); var person = new person{ name = "angie" }; svc.create(person); svc.delete(56); //delete person id 50
lets assume create throws exception on savechanges reason. when phone call delete, there still faulty person object in context, when delete method calls savechanges throw same exception.
of course of study can around instantiating new personservice in calling code screams wrong.
this leads me using new context each service method, mean method injection instead of constructor injection hoping avoid.
i've considered going repository/uow seems moves problem 1 layer deeper.
is method injection of context right way go or missing here?
thanks
entity-framework
No comments:
Post a Comment