Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let me say, when I started with MVC, I had the same problem. Then I learned about IoC (Inversion of Control) containers and Dependency Injection, it is so amazing on how much these things allow you to do.</p> <p>This project integrates Castle Windsor, NHibernate and ASP.NET MVC into one package. <a href="http://code.google.com/p/sharp-architecture/" rel="nofollow noreferrer">http://code.google.com/p/sharp-architecture/</a></p> <p>If you want to do it yourself, what you can do is pick your favorite IoC container. There are some bindings out there for MVC or you can roll your own. If you want to do your own, you have to implement a <code>IControllerFactory</code> and set MVC to use your factory. Here is mine.</p> <pre><code>public class ControllerFactory : IControllerFactory { private readonly IDependencyResolver _controllerResolver; private RequestContext RequestContext { get; set; } public ControllerFactory(IDependencyResolver controllerResolver) { _controllerResolver = controllerResolver; } public void ReleaseController(IController controller) { _controllerResolver.Release(controller); var disposableController = controller as IDisposable; if (disposableController != null) disposableController.Dispose(); } public IController CreateController(RequestContext requestContext, string controllerName) { Assert.IsNotNull(requestContext, "requestContext"); Assert.IsNotNullOrEmpty(controllerName, "controllerName"); RequestContext = requestContext; try { var controllerInstance = _controllerResolver.Resolve&lt;IController&gt;(controllerName.ToLower() + "controller"); return controllerInstance; } catch(Exception ex) { throw new HttpException(404, ex.Message, ex); } } } </code></pre>
 

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