InterceptWith() in StructureMap 3.x
本文关键字:StructureMap in InterceptWith | 更新日期: 2023-09-27 17:58:33
大家好,
目前,我正在尝试将部分代码从SM 2.X翻译为SM 3.X,但是拦截部分仍然存在一些问题。
也许更熟悉StructureMap的人可以帮助我?
container.IfTypeMatches(type => type.Equals(typeof(PageRepositoryDescriptor)))
.InterceptWith(i => new CustomPageRepositoryDescriptor());
代码来自EPiServer博客。
在Episerver社区论坛上也回答了类似的问题:http://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2016/8/structuremap-v2-vs-v3-syntax/
TL;DR-您应该能够通过在StructureMapv3:中使用此语法来获得所需的效果
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class InterceptModule : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.Services.Intercept<IContentRepositoryDescriptor>((locator, defaultService) =>
{
var pageRepositoryDescriptor = defaultService as PageRepositoryDescriptor;
return pageRepositoryDescriptor != null ?
new MyPageRepositoryDescriptor(pageRepositoryDescriptor) :
defaultService;
});
}
public void Initialize(InitializationEngine context)
{}
public void Uninitialize(InitializationEngine context)
{}
}