title: Autofac runtime parameters
body: <p>I'm new to autofac and looking to see the best practices on passing runtime values to constructor.  I've read a bunch of stackoverflow questions where this is asked but none are fully fleshed out.  Should we be using delegates, factory to create service etc.  I know passing the container around is not the best way to accomplish this.</p>
  
  <p>In my particular case I have a service that access multiple dependencies, say logging, dataprovider, etc.  Along with the few services being passed I also have run-time parameters I need to capture, say userid, password.  The userid and password are required for the SomeService and are looked up when a web viewer performs a particular action. Below is what I have and highlighted is the issue.</p>
  
  <pre><code>public class SomeService : ISomeService
  {
      private readonly IDataProvider _dataProvider;
      private readonly ILog _log;
      private readonly string _username;  
      private readonly string _password;
  
      public SomeService(IDataProvider dataProvider, ILog log,
          string username, string password)
      {
        _dataProvider = dataProvider;
        _log = log;
        _username = username;
        _password = password;
      }
  }
  </code></pre>
  
  <p>The dataprovider, and log are configured in autofac</p>
  
  <pre><code>builder.RegisterType&lt;DataProviderService&gt;().As&lt;IDataProvider&gt;()
  builder.RegisterType&lt;SomeLogService&gt;().As&lt;ILog&gt;()
  </code></pre>
  
  <p>Most of the functionality of this "SomeService" requires a username and password to verify before performing tasks, so figured it best to pass into constructor when creating but have never dealt with run-time requirements for autofac.  I've reviewed the question <a href="https://stackoverflow.com/questions/22259722/autofac-resolving-runtime-parameters-without-having-to-pass-container-around">Autofac - resolving runtime parameters without having to pass container around</a> and it seems close to what I need but need some more feedback on the best way to accomplish this.</p>