AI OnAI Off
Hi
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;
cp.RequestLifetime.InjectProperties(this);
base.OnInit(e);
}
publicIServiceClassServiceClass{get;set;}
(notice the public property)
The rest should be pretty much the same. Register on start up etc.
Hope this helps
Frederik
Nice, Thank's Frederik Vig. I use that with configuration https://code.google.com/p/autofac/wiki/WebFormsIntegration. But In general, it would be perfectly hide OnInit functionality. What better way to?
Thanks in advance
I guess yu could use an HttpModule or IInitializableModule instead of a base page. I personally prefer the base page though.
Hi.
In my project I want to use Dependency injection (Autofac). I found nice example (with setup dependency for IClinet (EPiServer Find)) on github https://github.com/200OK/TrufflerSample/blob/master/TrufflerSample/Global.asax.cs
for asp.net mvc, but I couldn't find example for asp.net webfroms.
I saw example http://joelabrahamsson.com/introducing-epimvp-a-framework-for-using-web-forms-mvp-with-episerver-cms/ but it requires a big change in my project.
What can you advise
Thanks in advance