Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First time I saw dependency injection to HttpModules in Spring.NET (not advertising this framework though). The idea is that you have special HttpModule which injects dependencies to other application-level HttpModule-s.</p> <p>Unfortunatelly current version of <a href="http://code.google.com/p/autofac/wiki/AspNetIntegration" rel="noreferrer">Autofac.Integration.Web</a> does not support this, but you can easily do that yourself:</p> <pre><code>public class MyModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication context) { Assert.IsNotNull(MyService); } public IMyService MyService { get; set; } } public class HttpModuleInjectionModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication context) { var containerProviderAccessor = context as IContainerProviderAccessor; if(containerProviderAccessor == null) throw new InvalidOperationException("HttpApplication should implement IContainerProviderAccessor"); var rootContainer = containerProviderAccessor.ContainerProvider.ApplicationContainer; foreach (string moduleName in context.Modules.AllKeys) rootContainer.InjectProperties(context.Modules[moduleName]); } } public class Global : HttpApplication, IContainerProviderAccessor { static IContainerProvider _containerProvider; protected void Application_Start(object sender, EventArgs e) { var builder = new ContainerBuilder(); builder.Register&lt;MyService&gt;().As&lt;IMyService&gt;(); _containerProvider = new ContainerProvider(builder.Build()); } public IContainerProvider ContainerProvider { get { return _containerProvider; } } } </code></pre> <p>HttpModuleInjectionModule should be registered before other HttpModule-s in web.config:</p> <pre><code> &lt;httpModules&gt; &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt; &lt;add name="HttpModuleInjection" type="WebTest.HttpModuleInjectionModule, WebTest"/&gt; &lt;add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule, Autofac.Integration.Web"/&gt; &lt;add name="PropertyInjection" type="Autofac.Integration.Web.PropertyInjectionModule, Autofac.Integration.Web"/&gt; &lt;add name="MyModule" type="WebTest.MyModule, WebTest"/&gt; &lt;/httpModules&gt; </code></pre> <p>I'm sure you can do similar things in Windsor. The difference would be in how you access your root container from <em>HttpModuleInjectionModule</em>.</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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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