如果c#中有多个装饰器包装器,如何注册Scrutor依赖项注入?
我能够为一级装饰类注册Scrutor DI
public interface IDecoratedService
{
void Function();
}
public class Decorator : IDecoratedService
{
private readonly IDecoratedService service
public void AdditionalFunction()
{
}
public void Function()
{
}
}
public class Decorated : IDecoratedService
{
private readonly Decorator decorator;
public Decorated( Decorator decorator)
{
this.decorator = decorator;
}
public void AdditionalFunction()
{
decorator.NewFunction();
decorator.Function();
}
public void Function()
{
}
}
//Scrutor DI Registration
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.Decorate<IDecoratedService, Decorated>();
到目前为止,一切都很好。
现在,我想包装OtherDecorator类。如何使用Scrutor在此处注册DI?
public class OtherDecorator : IDecoratedService
{
private readonly Decorated decorated;
public OtherDecorator( Decorated decorated )
{
this.decorated = decorated;
}
public void AdditionalFunction()
{
decorated.AdditionalFunction();
}
public void Function()
{
}
}