title: Use Dependency injection in WinForm Application
body: <p>I am using autofac in this scenario in my winform application. Its the first time am using autofac  and will needing details answer to my question below.</p>
  
  <p>I have the following code in my program.cs</p>
  
  <pre><code>ContainerBuilder autofac = new ContainerBuilder();
  
  autofac.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AsSelf().AsImplementedInterfaces();
  
  Container = autofac.Build();
  
  using (var scope = Container.BeginLifetimeScope())
  {
      var writer = scope.Resolve&lt;Application&gt;();
  }
  </code></pre>
  
  <p>In my Service i have the following code </p>
  
  <pre><code>public class A
  {
      Iservice _service
  
      public A(Iservice service)
      {
            _service=service
      }
  }
  </code></pre>
  
  <p>Now in my Form i need to call the service upon a button click. I can't seem to figure out how to continue as from here.How do i call the service now ? if i inject the interface in frmLogin constructor,i need to pass the interface as parameter there .Here my event code below</p>
  
  <pre><code>public frmLogin()
  {
      InitializeComponent();
  }
  public button_Click_Event(object sender,EventArgs e){
  
      //Service myservice= new Service();
  
  }
  </code></pre>