My application is built on MVC and entity framework using unit of work pattern and DDD.
Below is the code flow in controller action method.
- create a unit of work instance .
- create a domain service instance by passing the unit of work object to domainService constructor.
- call the appropriate method using domainService object, this method makes necessary changes to the entity objects.
- do commit(saveChanges) on unit of work.
If there is any unhandled domain exception thrown in step 3 (All the exceptions were handled in a mvc attribute and exception message is displayed on UI). If user corrects the data on UI and clicks on save, I am getting the below error in subsequent call to same action method
Error: "entity-object-cannot-be-referenced-by-multiple-instances-of-ientitychangetracker"
What happens to the DbContext if unhandled exception is thrown in web request? Is the context created in the previous web request remains active in the next web request? If yes, is that the reason why am getting the above exception?
If that's not the reason, will calling a dispose() on exception solves my problem ?