1

Hi all,
currently I'm trying to translate a part of code from SM 2.X to SM 3.X, but still have some problems with the interception part.

Maybe someone more familiar with StructureMap can help me with that?

container.IfTypeMatches(type => type.Equals(typeof(PageRepositoryDescriptor)))
    .InterceptWith(i => new CustomPageRepositoryDescriptor());

The code is from a EPiServer blog.

Steven
  • 166,672
  • 24
  • 332
  • 435

1 Answers1

0

A similar question was answered in the Episerver community forum here: http://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2016/8/structuremap-v2-vs-v3-syntax/

TL;DR - you should be able to get the desired effect by using this syntax in Structuremap v3:

[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)
   {}
}
Orjanh
  • 1