Is there a way in Autofac to register a type with a factory delegate that gets called when that type is requested?
Something like this:
builder.RegisterType<MyType>().AsSelf()
.WithFactory((IMyService s, ISomeDependency d) =>
{
var p1 = s.DoSomething();
var p2 = d.DoSomething(p1, true);
return new MyType(p1, p2);
});
This is probably not quite you expect, but does do the trick:
Or if you want to use automatic (constructor) injection, you can create a
MyTypesubclass (inside the Composition Root), that takes the two dependencies. This type can easily be registered: