Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Dependency injection in episerver web forms site



In my project I want to use Dependency injection (Autofac). I found nice example (with setup dependency for IClinet (EPiServer Find)) on github
for mvc, but I couldn't find example for webfroms.

I saw example but it requires a big change in my project.
What can you advise
Thanks in advance


Mar 29, 2013 15:54


I haven´t used Autofac before, but my guess is that in order to use dependency injection in web forms code-behind, you need to use property injection.

protected override void OnInit(EventArgs e)
        var cpa = (IContainerProviderAccessor)HttpContext.Current.ApplicationInstance;
        var cp = cpa.ContainerProvider;


(notice the public property)

The rest should be pretty much the same. Register on start up etc.

Hope this helps


Mar 31, 2013 8:56

Nice, Thank's Frederik Vig. I use that with configuration But In general, it would be perfectly hide OnInit functionality. What better way to?

Thanks in advance

Mar 31, 2013 22:43

I guess yu could use an HttpModule or IInitializableModule instead of a base page. I personally prefer the base page though.

Apr 01, 2013 9:12
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.