title: Configure Simple Injector to support resolving ASP.NET Core middleware dependencies?
body: <p>How can I configure SimpleInjector to resolve LogMiddleware's Invoke method dependency, like IMessageService ?</p>
  
  <p>As I know, Asp.net core uses HttpContext.RequestServices (IServiceProvider) to resolve dependencies, I set SimpleInjector container to HttpContext.RequestServices property but didn't work. I want to change ServiceProvider dynamically because each tenant should have a container.</p>
  
  <pre><code>public class LogMiddleware
  {
      RequestDelegate next;
      private readonly ILogger log;
  
      public LogMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
      {
          this.next = next;
          this.log = loggerFactory.CreateLogger&lt;LogMiddleware&gt;();
      }
  
      public async Task Invoke(HttpContext context, IMessageService messageService)
      {
           await context.Response.WriteAsync(
                  messageService.Format(context.Request.Host.Value));
      }
  }
  
  public interface IMessageService
  {
      string Format(string message);
  }
  
  public class DefaultMessageService : IMessageService
  {
    public string Format(string message)
    {
      return "Path:" + message;
    }
  }
  </code></pre>