-
-
Notifications
You must be signed in to change notification settings - Fork 844
Open
Labels
Description
Given the following service/container setup:
public class OuterService
{
public OuterService(IMiddleService middle) => Console.WriteLine("Outer");
}
public interface IMiddleService {}
public class MiddleService : IMiddleService
{
public MiddleService(InnerService inner) => Console.WriteLine("Middle");
}
public class InnerService
{
public InnerService() => Console.WriteLine("Inner");
}
builder.RegisterType<OuterService>().SingleInstance();
builder.RegisterType<MiddleService>().SingleInstance().As<IMiddleService>();
builder
.RegisterType<InnerService>()
.SingleInstance()
.OnActivated(_ => Console.WriteLine("Inner activated"))
;
I observe the following output on resolving OuterService
:
Inner
Middle
Outer
Inner activated
Note that activation event fires last (which allows us, for example, resolve circular dependency, were Inner
to depend on Outer
).
Now we add a decorator (everything else stays the same):
public class Decorator : IMiddleService
{
public Decorator(IMiddleService inner) => Console.WriteLine("Decorator");
}
builder.RegisterDecorator<Decorator, IMiddleService>();
The output is:
Inner
Middle
Decorator
Inner activated
Outer
Now the activation event fires after decorator, not the last in the pipeline (which in our case brings back circular dependency).
Observed on Autofac 6.2 and 6.5.
dropsonic