Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>If I wasn't using an DI container, I wouldn't have to reference EntityFramework library in my MVC3 app, only my business layer which would reference my DAL/Repo layer.</p> </blockquote> <p>You can create a seperate project called "DependencyResolver". In this project you have to reference all your libraries.</p> <p>Now the UI Layer doesn't need NHibernate/EF or any other not UI relevant library except of Castle Windsor to be referenced.</p> <p>If you want to hide Castle Windsor and DependencyResolver from your UI layer you could write an HttpModule which calls the IoC registry stuff.</p> <p>I have only an example for StructureMap:</p> <pre><code>public class DependencyRegistrarModule : IHttpModule { private static bool _dependenciesRegistered; private static readonly object Lock = new object(); public void Init(HttpApplication context) { context.BeginRequest += (sender, args) =&gt; EnsureDependenciesRegistered(); } public void Dispose() { } private static void EnsureDependenciesRegistered() { if (!_dependenciesRegistered) { lock (Lock) { if (!_dependenciesRegistered) { ObjectFactory.ResetDefaults(); // Register all you dependencies here ObjectFactory.Initialize(x =&gt; x.AddRegistry(new DependencyRegistry())); new InitiailizeDefaultFactories().Configure(); _dependenciesRegistered = true; } } } } } public class InitiailizeDefaultFactories { public void Configure() { StructureMapControllerFactory.GetController = type =&gt; ObjectFactory.GetInstance(type); ... } } </code></pre> <p>The DefaultControllerFactory doesn't use the IoC container directly, but it delegates to IoC container methods.</p> <pre><code>public class StructureMapControllerFactory : DefaultControllerFactory { public static Func&lt;Type, object&gt; GetController = type =&gt; { throw new InvalidOperationException("The dependency callback for the StructureMapControllerFactory is not configured!"); }; protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { if (controllerType == null) { return base.GetControllerInstance(requestContext, controllerType); } return GetController(controllerType) as Controller; } } </code></pre> <p>The <code>GetController</code> delegate is set in a StructureMap Registry (in Windsor it should be an Installer).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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