title: Injecting NServiceBus using structuremap without global.asax
body: <p>I am new to NServiceBus and struggling to inject IBus in my controller using structure map. Actually after doing a little research i found that we can inject it by putting below code in Application_Start event of global.asax -</p>
  
  <pre><code>protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
  
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
  
          Configure.With()
                   .Log4Net()
                   .StructureMapBuilder()
                   .XmlSerializer()
                   .MsmqTransport()
                   .IsTransactional(false)
                   .PurgeOnStartup(false)
                   .UnicastBus()
                   .ImpersonateSender(false)
                   .CreateBus();
      }
  </code></pre>
  
  <p>and in my controller I can use IBus as property or constructor injection:</p>
  
  <pre><code>private IBus Bus { get; set; }
      private ITest Test { get; set; }
  
      public MyLinkController(IBus bus, ITest test)
      {
          Bus = bus;
          Test = test;
      }
  </code></pre>
  
  <p>This works fine and inject bus without any problem. But my problem is I do not have control over global.asax, so i want to put the configuration somewhere else e.g. i tried putting it in structuremap registry like below:</p>
  
  <pre><code>For&lt;IBus&gt;().Use(
              () =&gt;
                  NServiceBus.Configure.With()
                                           .Log4Net()
                                           .StructureMapBuilder()
                                           .XmlSerializer()
                                           .IsTransactional(true)
                                           .PurgeOnStartup(false)
                                           .UnicastBus()
                                           .ImpersonateSender(false)
                                           .CreateBus()
                                           .Start()
                  );
  </code></pre>
  
  <p>But it doesn't help. Looks like structure map needs to know the configuration before its own initialization.
  So is there any way to do it without application_start event?</p>