I am misunderstanding the Autofac documentation on passing parameters to a Resolve method. The following is a minimalistic example of what I mean:
Example
https://dotnetfiddle.net/fz5eTp
public static void Main()
{
var cb = new ContainerBuilder();
cb.RegisterType<A>();
cb.Register<B>((c, p) => new B(p.TypedAs<C>()));
using (var c = cb.Build())
{
// works
c.Resolve<B>(TypedParameter.From(new C()));
// fails
c.Resolve<A>(TypedParameter.From(new C()));
}
}
public class A { public A(B b) { } }
public class B { public B(C c) { } }
public class C { }
Expected
I expected the TypedParameter to get passed down to B class.
Unfortunately the Exception message "Sequence contains no elements" suggests that no parameter was passed down.
Question
How can I pass parameters (only known at Resolve time) down to lower level constructors? Or in this specific example, how do I pass a C parameter down to B, when resolving a A.