How to use autofac with .net form application with parameters

Viewed 13

I want to use autofac in an existing .net form application. The application is designed in such a way that one form calls another form. I cannot add other parameters because one form uses parameters while using the other form. How do I use autofac on these forms?

Code sample

//program.cs
Form1 form1 = Form1(Container.Resolve<ISample>(());
Application.Run(form1);

//form1.cs
private ISample _sample;
Form1 (ISample sample){
   _sample = sample;
   Form2 form2 = Form2(“testdata”, “testdata2”);
   form2.show();
}

//form2.cs
Form2 (string testdata1, string testdata2){
    //How can we use autofac here? Is the following usage correct?  
    IAnotherSample anatherSample = Container.Resolve<IAnotherSample>(()
}
0 Answers
Related