2016-04-12 218 views
1

在一個ASP.NET MVC 5應用程序,我有以下StructureMap配置:DecorateAllWith在Autofac和Asp.Net核心

cfg.For(typeof (IRequestHandler<,>)).DecorateAllWith(typeof (MediatorPipeline<,>)); 

http://structuremap.github.io/interception-and-decorators/

我現在使用ASP.NET核心...

Autofac中是否有等效的DecorateAllWith等效配置?

+0

你能描述一下'DecorateAllWith'嗎? –

+1

你能在這裏檢查http://docs.autofac.org/en/latest/advanced/adapters-decorators.html –

+0

嘿米格爾你會介意共享meditr的autofac設置嗎? –

回答

2

是的,你可以做這樣的事情:

builder.RegisterGeneric(typeof(RequestHandler<>)) 
    .Named("requestHandler", typeof(IRequestHandler,<>)); 

然後:

builder.RegisterGenericDecorator(typeof(MediatorPipeline<,>), 
    typeof(IRequestHandler<,>), fromKey: "requestHandler"); 

您可以查看完整的文檔here