【问题标题】:Decorate a WCF service with Autofac使用 Autofac 装饰 WCF 服务
【发布时间】:2018-02-27 12:11:55
【问题描述】:

我想用以下设置来装饰 WCF 服务:

SVC 定义

<%@ ServiceHost Language="C#" Debug="true" 
    Service="Foo.IBarService, Foo"
    Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"%>

Autofac 注册

builder.RegisterType<FooService>().Named<IFooService>("fooservice");

builder.RegisterType<LogFooService>().Named<IFooService>("logfooservice");

builder
    .RegisterDecorator<IFooService>(
        (context, inner) => context.ResolveNamed<IFooService>("logfooservice", TypedParameter.From(inner)),
        fromKey: "fooservice")
    .As<IFooService>();

当装饰器不是服务本身时,这种方法确实有效。因此,例如在构造函数中带有修饰的 IWhatever 的具体服务。 svc 服务有什么不同?

【问题讨论】:

  • 这里没有太多可做的。查看错误输出、服务合同等会很有帮助。

标签: wcf dependency-injection autofac decorator


【解决方案1】:

docs 状态:

标准 Autofac 服务托管几乎适用于所有情况,但如果您在 WCF 服务实现中使用装饰器,那么您需要使用多租户 WCF 服务托管机制而不是标准 Autofac 服务托管。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多