Try our conversational search powered by Generative AI!

Structuremap v2 vs v3 syntax


Hi there,

In structuremap v2 we could do this:

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

However, things moved around in v3, so I had to rewrite that expression. I figured I could do this:

container.For().Use(new PageNodeTooltipDescriptor());

However, I can't seem to inject my custom class by doing this. If I set a break point on my overridden property within PageNodeTooltipDescriptor, it'll never hit that break point.

Any advice?


Aug 22, 2016 15:05


When I look at the quick start of StructureMap shouldn't the right code be like this?:


Maybe you've already tried.

Jan Kees


Aug 22, 2016 15:58

Looks like you are using it as a decorator in the first example? For structuremap you can then use the decorateallwith extension to add a decorator type of class on top of the current instance.

Edited, Aug 22, 2016 22:23

Thanks - I've already tried both suggestions actually;


Aug 23, 2016 8:33

...and if you only use the top line?


Aug 23, 2016 10:24

Sorry, I meant that I've tried both lines individually, so yes I've tried only that line as well :-)

Aug 23, 2016 10:39

The class PageRepositoryDescriptor is registered in IOC container for abstraction IContentRepositoryDescriptor. One approach is to use the Intercept feature that was introduced in 9.10 (see There in your factory delegate where you will get in an instance of IContentRepositoryDescriptor you could see if it is an instance of PageRepositoryDescriptor in which case you can return your decorator otherwise you return the default service. Something like:

    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) :

        public void Initialize(InitializationEngine context)

        public void Uninitialize(InitializationEngine context)
Aug 23, 2016 11:19

That did it. Thanks!

Aug 24, 2016 15:05

So to fully understand, the instance of the PageRepositoryDescriptor class is already registered by EPiServer on startup so you need to intercept it from the repository?

Aug 25, 2016 13:25

Yes in this case he wants to change the behaviour of the default type PageRepositoryDescriptor (that is registered in IOC container).

Intercept is designed as a decorator pattern where you can register a new type in the container where the new type has access to the default/old type so it can delgates calls back to the default implementations.

Aug 26, 2016 10:22

I blogged a little bit about decorator pattern here if that helps...

It's mainly used to tweak the original implementation a little...
It's similar to inheriting the original class but has a few pros since you can stack multiple decorators in any order you wish. The con is that you are limited to use the same interface so you can't add new methods. I mainly use it for solving cross cutting concerns like logging, caching etc. 

Aug 26, 2016 10:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.