title: c# WCF [Simple Injectior] injection pattern
body: <p>I have seen lots of examples on how to do this, but as I am a newbie to DI, I thought it best to ask a question specifically for my issues. Again, I apologize if this has been asked already.</p>
  
  <p>We have a C# WCF service that is working, but I have recently been asked to implement a DI framework for reuse ability. After looking around I have chosen Simple Injector. </p>
  
  <p>So my service currently compiles and I can view the WSDL from a browser.</p>
  
  <p>To start I have placed the initialization code that sets up the container in a Global.asax file in the Application_Start function. Within this function I have the following code:</p>
  
  <pre><code>var container = new Container();
  container.Options.DefaultScopedLifestyle = new WcfOperationLifestyle();
  </code></pre>
  
  <p>followed by my registrations:</p>
  
  <pre><code>container.Register&lt;IPersonManager, PersonManager&gt;();
  etc....
  </code></pre>
  
  <p>finally, I run:</p>
  
  <pre><code>SimpleInjectorServiceHostFactory.SetContainer(container);
  </code></pre>
  
  <p>This runs correctly, no errors and I can break point onto the fisrt line above and step through the code.</p>
  
  <p><em>I have been told that I should use a different location for the initialization code and not use a global.asax file.</em> <strong>Not sure if I should change this.</strong></p>
  
  <p>OK.</p>
  
  <p>When I look at the constructor for the PersonManager class, I am passing an object that also implements the IPersonManager interface.</p>
  
  <p><em>I am assuming this is the correct way of doing this.</em> So as long as the object implements the IPersonManager interface it will be injected in. <strong>Not sure about this either</strong></p>
  
  <p>Anyway, </p>
  
  <p>I have a class, the code is as follows:</p>
  
  <pre><code>public static class AddressRepository
  {
      public static void SetAddress(this IRepository&lt;Address&gt; AddressRepository)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>And I have tried to set the Simple Injector initialisation for this as follows:</p>
  
  <pre><code>container.Register(typeof(IRepository&lt;&gt;), typeof(Address), Lifestyle.Scoped);
  </code></pre>
  
  <p>This does not work. I guess because the AddressRepository does not implement an interface, but the method does. </p>
  
  <p>Is it possible to inject into this method and if so how is it done.</p>