C# 在Autofac中装饰现有注册

C# 在Autofac中装饰现有注册,c#,.net,autofac,C#,.net,Autofac,我有以下接口及其实现: public interface IService { } public class Service1 : IService { } public class DecoratedService { public DecoratedService(IService inner) { } } Service1已在我无法更改的代码中注册(未命名注册): builder.RegisterType().As(); 所以我需要用我自己的来装饰这个注册。

我有以下接口及其实现:

public interface IService
{
}

public class Service1 : IService
{
}

public class DecoratedService
{
    public DecoratedService(IService inner)
    {
    }
}
Service1已在我无法更改的代码中注册(未命名注册):

builder.RegisterType().As();
所以我需要用我自己的来装饰这个注册。如何在对性能影响最小的情况下实现这一点

公共类数据模块:自动传真模块

上课


如果我需要用指定的iSeries注册更改现有iSeries注册,这没关系(但我还没有找到方法)。我在stackoverflow中研究了所有相关问题,但没有一个问题给了我解决方案。

您应该能够替换模块中现有的
iSeries设备注册,并提供一个名称

builder.RegisterType<Service1>().Named<IService>("implementor");
builder.RegisterType().Named(“实现者”);
然后为命名服务注册一个decorator

builder.RegisterDecorator<IService>(s => new DecoratedService(s), "implementor");
builder.RegisterDecorator=>新的装饰服务,“实现者”;
Nick发表了一篇博客文章,详细介绍了Autofac中的装饰器支持


您应该能够替换模块中现有的
iSeries设备注册,并为其提供名称

builder.RegisterType<Service1>().Named<IService>("implementor");
builder.RegisterType().Named(“实现者”);
然后为命名服务注册一个decorator

builder.RegisterDecorator<IService>(s => new DecoratedService(s), "implementor");
builder.RegisterDecorator=>新的装饰服务,“实现者”;
Nick发表了一篇博客文章,详细介绍了Autofac中的装饰器支持


是的,这是一个有趣的想法。值得一试,这是一个有趣的想法。值得一试