I am trying to use a decorator in Autofac with a delegate factory but I can't seem to get it to resolve the parameters.
public interface IFoo
{ }
public class Foo : IFoo
{
public Foo(string bar)
{ ... }
}
public class DecoratedFoo : IFoo
{
public DecoratedFoo(IFoo decorated)
{ ... }
}
I would like to inject into a service like so:
public SomeService(Func<string, IFoo> factory)
{
// I would expect IFoo to be a DecoratedFoo here
IFoo foo = factory("hello");
}
I have registered components like so:
builder.RegisterType<Foo>()
.Named<IFoo>("foo")
.UsingConstructor(typeof(string));
builder.RegisterDecorator<IFoo>(
(ctx, inner) => new DecoratedFoo(inner),
fromKey: "foo");
I get an error saying it cannot resolve my parameter bar. This is a simplified example but I won't know what the value of bar is (hence using the factory).
Is there any way to accomplish what I'm doing?