How to resolve instance with Autofac and Asp.Net MVC -


I have just begun to try Autophack and I think I can solve the concrete classes with myself I am confusing.

I managed to register my interface for my concrete sections in the form of

  builder.RegisterType & lt; TestClass & gt; () In form of. & Lt; ITest & gt; (); Var Container = Builder Build (); Dependency Resolver. SetsSolar (New Autofacked-Dependency Resolver (Container));  

It makes sense that the problem I am having is that what is the example in my MVC controller? Most things I have read is that I need to create a new instance of ContainerBuilder and then call the scope. Resolve method, but of course it is bad behavior and every controller should not be needed?

I think the confusion is when and how can you use the container so that I can call the solution method and when I need it, I can call it.

I am a novice on this as you probably have guessed!

One way to do this is to use the controller constructor because AutoFac will handle it for you:

  public class MyController: controller {Private ITest _test; Public MyController (ITAST Test) {_test = test; }}  

If you do not want to use the constructor and allow you to inject dependence, you can do this in your controller action method:

  var test = dependency resolver Present. Gateswire & lt; ITAST & gt; ()  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -