title: Autfac injecting service that has parameter in constructor
body: <p>I understand how to inject a nullable parameter into a constructor using <strong>TypedParameter</strong> in the <a href="https://autofaccn.readthedocs.io/en/latest/register/parameters.html#available-parameter-types" rel="nofollow noreferrer">autofac docs</a>.  I am struggling to understand how to then inject that service into another service, where the parameter will come from.  Here is some example code:</p>
  
  <pre><code>// interface
  pubic Interface IProvider 
  {
      string GetParameter();
  }
  
  // implementation
  public class Provider : IProvider
  {
      private readonly int? _parameterId;
      public Provider(int? parameterId){
          _parameterId = parameterId;
      }
      public string GetParameter(){
           // go get my parameter from wherever using int that was passed to constructor
      }
  }
  </code></pre>
  
  <p>Now in my api controller i might inject this service so i can get a parameter:</p>
  
  <pre><code>public class ParameterController : ApiController
  {
      private readonly IProvider _provider;
      public ParameterController(IProvider provider){
           _provider = provider;
      }
      [HttpGet]
      public string GetParameterNoInput(){
           _provider.GetParameter(null);
      }
      [HttpGet]
      public string GetParameter(int input){
          // my provider wants this input but not as a passed parameter
          // I don't know how to do this
      }
   }
  </code></pre>
  
  <p>And of course the registration</p>
  
  <pre><code>builder.RegisterType&lt;Provider&gt;().As&lt;IProvider&gt;().InstancePerRequest()
     .WithParameter(new TypedParameter(typeof(Guid?), "parameterId"));
  </code></pre>
  
  <p>FWIW, I am aware this isn't a great design choice but it is what is being dictated to me.  What is the pattern for dealing with this in autofac?  To clarify, the part that is being dictated is that IProvider has the nullable int parameterId injected to it rather than having exposed methods that accept the the int</p>
  
  <p>Should i be doing something like this in my controller:</p>
  
  <pre><code>Func&lt;int?&gt;, IProvider _newProvider;
  public ParameterController(Func&lt;int?, IProvider&gt; provider){
      _newProvider = provider;
  }
  
  // and then in my api i can do
  [HttpGet]
  public string GetParameter(int input){
      var provider = _newProvider(input);
      provider.GetParameter();
  }
  </code></pre>