title: using Autofac with XML configuration
body: <p>I am trying to decouple an implementation where the interface is know and the implementation would be defined in App.Config. But it does not seem to be able to resolve the interface.</p>
  
  <p>This is what I am doing :</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;configuration&gt;
    &lt;autofac defaultAssembly="My.Service"&gt;    
      &lt;components&gt;
        &lt;component type="My.Services.Service, My.Service" 
                   service="My.Abstractions.IService, My.Service" 
                   instance-scope="per-lifetime-scope" 
                   instance-ownership="lifetime-scope"
                   name="Service"
                   inject-properties="no"/&gt;  
      &lt;/components&gt;    
    &lt;/autofac&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And in my c# code</p>
  
  <pre class="lang-cs prettyprint-override"><code>var builder = new ContainerBuilder();
  builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
  var container = builder.Build();
  IService service = container.Resolve&lt;IService&gt;()
  </code></pre>
  
  <p>When I run the code it is not able to resolve the IService, which is what I need. 
  If I do the same but with the implementation in code instead of xml this is how it works.</p>
  
  <pre class="lang-cs prettyprint-override"><code>var builder = new ContainerBuilder();
  builder.RegisterType&lt;Service&gt;().As&lt;IService&gt;().InstancePerLifetimeScope();
  var container = builder.Build();
  IService service = container.Resolve&lt;IService&gt;()
  </code></pre>
  
  <p>And here is the stacktrace</p>
  
  <pre class="lang-none prettyprint-override"><code>An exception occurred creating the service: IService ---&gt; Autofac.Core.Registration.ComponentNotRegisteredException: 
  The requested service 'My.Abstractions.IService' has not been registered. 
  To avoid this exception, either register a component to provide the service,
  check for service registration using IsRegistered(), 
  or use the ResolveOptional() method to resolve an optional dependency.
     at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
     at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
     at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context,IEnumerable`1 parameters)
     at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
  </code></pre>
  
  <p>Can anyone explain me how I can resolve the interface when using xml configuration?</p>