Friday 15 July 2011

asp.net mvc - What is the correct place to dispose a repository created in a custom controller factory? -


In my ASP.NET MVC project, I use a custom Controller Factory, which instructs and passes an entity framework-based data repository.

The manufacturer's creator creates the repository object IDisposable, but how should I resolve it? The simplest approach that comes to mind is to override the controller's disposal method and to do it there, but since the controller was injected into the controller and there was not made, the settlement in the controller does not seem right to me. is.

In your repository, you must use the ANTI Framework data references within a statement. This means that after the access to data access, the reference method will be called in relation to closing the connection.

 using  (var context = new MyDbContext ()) {// do your data access}    

No comments:

Post a Comment