November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi,
When I look at the quick start of StructureMap shouldn't the right code be like this?:
container.For<PageRepositoryDescriptor>().Use<PageNodeTooltipDescriptor>();
Maybe you've already tried.
Jan Kees
Reference: http://structuremap.github.io/registration/
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.
x.For<IDevice>().DecorateAllWith<DecoratorIWantInFront>();
Thanks - I've already tried both suggestions actually;
container.For<PageRepositoryDescriptor>().DecorateAllWith<PageNodeTooltipDescriptor>(); container.For<PageRepositoryDescriptor>().Use<PageNodeTooltipDescriptor>();
...and if you only use the top line?
container.For<PageRepositoryDescriptor>().DecorateAllWith<PageNodeTooltipDescriptor>();
Sorry, I meant that I've tried both lines individually, so yes I've tried only that line as well :-)
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 http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Initialization/dependency-injection/). 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:
[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) {} }
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?
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.
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.
Hi there,
In structuremap v2 we could do this:
However, things moved around in v3, so I had to rewrite that expression. I figured I could do this:
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?
Thanks!