title: Rebind service in runtime
body: <p>I'm writing an app which reads messages from rabbitmq. A message contains a user's name and a correlation ID. There is a message handler which performs some calculations based on the message's payload and writes logs as well. A log entry must contain a user's name and a correlation ID from the message.</p>
  
  <p>So, for each message, a new instance of MessageProcessor is created and a new instance of ExecutionContext should be created as well. </p>
  
  <p>I'm using <code>Microsoft.DependencyInjection</code> which comes with .net core and I can't achieve the desired behaviour.</p>
  
  <p>I tried to use <code>Replace</code> method but it did not work.</p>
  
  <p>MessageProcessor.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>internal sealed class MessageProcessor
  {
      public MessageProcessor(ILogger logger) 
      {
      }
  
      public async Task Process(Message message)
      {
          // do something useful
          this.logger.WriteInfo("Message has been processed");
      }
  
  }
  </code></pre>
  
  <p>Logger.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>internal sealed class Logger
  {
      public Logger(ExecutionContext context)
      {
          //context contains UserName and CorrelationID
      }
  }
  </code></pre>
  
  <p>Is it a good idea to rebind <code>ExecutionContext</code> for each message? Are there better solutions?</p>