Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any benefit to using single Repository instance for Asp.net Mvc application?
    text
    copied!<p>In <a href="http://www.codeplex.com/CarTrackr" rel="nofollow noreferrer">CarTrackr project</a>, It use some technique that creates only 1 repository instance for all request in Asp.net Mvc website and uses UnityControllerFactory class to manage all repository instanes(send to requested controller). </p> <p>Is there any benefit to using single repository instance when compare with creating new repository instance every request? </p> <p>I know, it may improve overall performance. But, Does it cause any transcation problem?</p> <p><strong>partial Global.asax</strong></p> <pre><code>public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { RegisterRoutes(RouteTable.Routes); RegisterDependencies(); } protected static void RegisterDependencies() { IUnityContainer container = new UnityContainer(); // Registrations container.RegisterType&lt;IUserRepository, UserRepository&gt;(new ContextLifetimeManager&lt;IUserRepository&gt;()); container.RegisterType&lt;ICarRepository, CarRepository&gt;(new ContextLifetimeManager&lt;ICarRepository&gt;()); // Set controller factory ControllerBuilder.Current.SetControllerFactory( new UnityControllerFactory(container) ); } } </code></pre> <p><strong>partial CarController.cs</strong></p> <pre><code>[Authorize] public class CarController : Controller { private IUserRepository UserRepository; private ICarRepository CarRepository; public CarController(IUserRepository userRepository, ICarRepository carRepository) { UserRepository = userRepository; CarRepository = carRepository; } } </code></pre> <p><strong>Thanks,</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload