title: Create resource at runtime for Web Api controller
body: <p>My application is multi tenant right now and I have a class that looks up which settings to use based on which tenant is logged in. So I have some code in every controller that essentially looks like this.</p>
  
  <pre><code>[RoutePrefix("api/client/{id})]
  public class ReportsController : ApiController
  {
      ILogHandler _logHandler = new LogHandler();
      private processor _processor = null;
  
      public ReportsController(IProcessor Processor)
      {
          _processor = Processor;
      }
  
      [Route("")]
      [HttpGet]
      [EnableQuery]
      public IHttpActionResult Get(Guid id)
      {
              //Some pseudo code here to get some settings for a client
              var settings = clientSettings(id);
  
              //investigate the settings
              if(settings.CanDoSomething())
                  var qi = _processor.process();
              return Ok(qi);
      }
  }
  </code></pre>
  
  <p>I look up some settings and decide to do some stuff. My problem is every single controller has to do the lookup process but what I'd like to do is have the object already be there and scoped to the correct client. </p>
  
  <p>I tried using Owin middleware and putting the object in the Owin environment but I guess it's to early in the pipeline and I don't know what the value of the <code>Id</code> is in the middleware.</p>
  
  <p>I also have autofac and I've looked into using <a href="http://docs.autofac.org/en/latest/advanced/multitenant.html#asp-net-integration" rel="nofollow">multitenant</a> but that appears to be more geared toward resolving specific dependencies per tenant or giving tenants access to certain controllers. What I'm after is every tenant gets one of these objects each request but it just needs different setup. </p>