c# - dependency injection into a console app -


this question has answer here:

we use autofac simple dependency injection in our web app. it's configured , registered in classes operate behind-the-scenes. makes injecting stuff in our project painless easy this:

//interface public interface isuperhereservice { }  //class uses interface public class superherofactory {     public isuperheroservice superheroservice { get; }      public superherofactory(isuperheroservice superheroservice)     {        superheroservice = superheroservice;         ...do our stuff... 

however had create separate project console app. console app has main method.

i'm not @ sure how inject interface main method.

is possible?

thanks!

create , configure container in main (or in methods called main.) resolve instance of superherofactory container , call whatever methods need to.

someone may object shouldn't resolve directly container. that's true, main composition root. it's we're supposed reference container, it's appropriate there.


Comments