title: NServiceBus fails to process message: The requested service 'NServiceBus.Impersonation.ExtractIncomingPrincipal' has not been registered
body: <p>I am receiving an error when using NServiceBus 4.0.3 with NHibernate 3.3.1 when it's trying to process a message</p>
  
  <pre><code>    INFO  NServiceBus.Unicast.Transport.TransportReceiver [(null)] &lt;(null)&gt; - Failed to process message
  Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'NServiceBus.Impersonation.ExtractIncomingPrincipal' 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 NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 353
     at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 233
     at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.ProcessMessage(TransportMessage message) in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Transports\Msmq\MsmqDequeueStrategy.cs:line 262
     at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action() in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Transports\Msmq\MsmqDequeueStrategy.cs:line 197
  2013-08-30 09:35:02,508 [9] WARN  NServiceBus.Faults.Forwarder.FaultManager [(null)] &lt;(null)&gt; - Message has failed FLR and will be handed over to SLR for retry attempt: 1, MessageID=8aaed043-b744-49c2-965d-a22a009deb32.
  </code></pre>
  
  <p>I think it's fairly obvious what that I need to implement or register an "ExtractIncomingPrincipal", but I can't seem to find any documentation on how or whether there is a default one that I can use. I wouldn't have figured that I would have had to register any of the NServiceBus-related services as many of them are already being registered in my IoC implementation.</p>
  
  <p>As requested, here is the EndpointConfig and supporting code I have currently:</p>
  
  <pre><code>[EndpointSLA("00:00:30")]
  public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization {
      public void Init() {
          Configure.With().ObjectBuilderAdapter().UseInMemoryTimeoutPersister().UseInMemoryGatewayPersister().InMemorySagaPersister().InMemorySubscriptionStorage();
     }
  }
  
  //public class PrincipalExtractor : ExtractIncomingPrincipal {
  //    public IPrincipal GetPrincipal(TransportMessage message) {
  //        return Thread.CurrentPrincipal;
  //    }
  //}
  
  public class ObjectBuilderAdapter : IContainer {
      readonly IDependencyInjector injector;
  
      public ObjectBuilderAdapter(IDependencyInjectionBuilder dependencyInjectionBuilder) {
          injector = dependencyInjectionBuilder.Create(); //This method does all the common service registrations that I am trying to re-use
          //injector.RegisterType&lt;ExtractIncomingPrincipal, PrincipalExtractor&gt;();
      }
  
      public void Dispose() {
          injector.Dispose();
      }
  
      public object Build(Type typeToBuild) {
          return injector.Resolve(typeToBuild);
      }
  
      public IContainer BuildChildContainer() {
          return new ObjectBuilderAdapter(new DependencyInjectorBuilder());
      }
  
      public IEnumerable&lt;object&gt; BuildAll(Type typeToBuild) {
          return injector.ResolveAll(typeToBuild);
      }
  
      public void Configure(Type component, DependencyLifecycle dependencyLifecycle) {
          injector.RegisterType(component);
      }
  
      public void Configure&lt;T&gt;(Func&lt;T&gt; component, DependencyLifecycle dependencyLifecycle) {
              injector.RegisterType(component);
      }
  
      public void ConfigureProperty(Type component, string property, object value) {
          if (injector is AutofacDependencyInjector) {
            ((AutofacDependencyInjector)injector).ConfigureProperty(component, property, value);
          } else {
              Debug.WriteLine("Configuring {0} for property {1} but we don't handle this scenario.", component.Name, property);
          }
      }
  
      public void RegisterSingleton(Type lookupType, object instance) {
          injector.RegisterInstance(lookupType, instance);
      }
  
      public bool HasComponent(Type componentType) {
          return injector.IsRegistered(componentType);
      }
  
      public void Release(object instance) { }
  }
  
  public static class Extensions {
      public static Configure ObjectBuilderAdapter(this Configure config) {
          ConfigureCommon.With(config, new ObjectBuilderAdapter(new DependencyInjectorBuilder()));
          return config;
      }
  }
  </code></pre>