title: Autofac IComponentContext.Resolve With Parameters
body: <p>How would one provide an IComponentContext func to a type Registration where the parameters could be either types (to be resolved) or parameters passed in?</p>
  
  <p>So if I have a func I'd like to use for registration such as this: </p>
  
  <pre><code>    public static ClassTarget Resolver(ClassArg1 arg1, ClassArg2 arg2)
      {
          // Do something fancier than this...
          return new ClassTarget(arg1, arg2);
      }
  </code></pre>
  
  <p>How would I register that for <code>ClassTarget</code>?</p>
  
  <p>A full example, with the hack I'm currently using and alternate registration that work (as one would expect): </p>
  
  <pre><code>public class ClassArg1 { }
  
  public class ClassArg2 { }
  
  public class ClassTarget
  {
      public ClassTarget(ClassArg1 arg1, ClassArg2 arg2) {  }
  }
  
  public static class ResolveFuncTest
  {
      public static ClassTarget Resolver(ClassArg1 arg1, ClassArg2 arg2)
      {
          // Do something fancier than this...
          return new ClassTarget(arg1, arg2);
      }
  
      private static T GetArgValue&lt;T&gt;(IComponentContext componentContext, IEnumerable&lt;Parameter&gt; parameters)
      {
          if (parameters != null)
          {
              var param = parameters.OfType&lt;TypedParameter&gt;().FirstOrDefault(p =&gt; p.Type == typeof(T));
              if (param != null)
              {
                  return (T)param.Value;
              }
          }
  
          return componentContext.Resolve&lt;T&gt;();
      }
  
      public static void Test()
      {
          var builder = new ContainerBuilder();
  
          // The first argument will be resolved as normal
          builder.RegisterType&lt;ClassArg1&gt;().AsSelf().SingleInstance();
  
          // Works - just a typical type registration without the Func used
          //builder.RegisterType&lt;ClassTarget&gt;().AsSelf().SingleInstance();
          // Works - but only if we know how to resolve the arguments as types or parameters
          //builder.Register((c, p) =&gt; Resolver(c.Resolve&lt;ClassArg1&gt;(), p.TypedAs&lt;ClassArg2&gt;())).AsSelf().SingleInstance();
          // Works - smells though!
          builder.Register((c, p) =&gt; Resolver(GetArgValue&lt;ClassArg1&gt;(c,p), GetArgValue&lt;ClassArg2&gt;(c, p))).AsSelf().SingleInstance();
  
          // Build/scope
          var context = builder.Build();
          var scope = context.BeginLifetimeScope();
  
          // The second argument is passed as an instance/parameter at resolve time
          scope.Resolve&lt;ClassTarget&gt;(new TypedParameter(typeof(ClassArg2), new ClassArg2()));
      }
  }
  </code></pre>
  
  <p>Clearly I misunderstand something core here, since I'm stumbling over myself to do the parameter resolution that Autofac normally does so seamlessly!  Is there just another overload to <code>Resolve</code> I'm missing in the documentation?</p>