AI OnAI Off
Hi Jens,
Yes, it is possible.
EPiServer.Web.Routing.UrlResolver is an abstract class, and episerver's default implementation is EPiServer.Web.Routing.Internal.DefaultUrlResolver.
That class is decorated with ServiceConfiguration attribute like this:
[ServiceConfiguration(Lifecycle = ServiceInstanceScope.Singleton, ServiceType = typeof (UrlResolver))] public class DefaultUrlResolver : UrlResolver { ... }
You can create your own implementation
public class MyUrlResolver : UrlResolver { ... }
And tell EPiServer to use your implementation like this:
[ModuleDependency(typeof(ServiceContainerInitialization))] public class MyUrlResolverInitModule : IConfigurableModule { public void ConfigureContainer(ServiceConfigurationContext context) { context.Container.Configure( x => { x.For<UrlResolver>().Singleton().Use<MyUrlResolver>(); }); } public void Initialize(InitializationEngine context) { } public void Uninitialize(InitializationEngine context) { } }
Implementing all UrlResolver's methods can be quite tricky, so if you just want to test if your IoC setup works, your can implement MyUrlResolver like this:
public class MyUrlResolver : DefaultUrlResolver { public MyUrlResolver( RouteCollection routes, IContentLoader contentLoader, ISiteDefinitionRepository siteDefinitionRepository, TemplateResolver templateResolver, IPermanentLinkMapper permanentLinkMapper, IContentLanguageSettingsHandler contentLanguageSettingsHandler) : base( routes, contentLoader, siteDefinitionRepository, templateResolver, permanentLinkMapper, contentLanguageSettingsHandler) { } }
Inject UrlResolver in your page controller and check if MyUrlResolver or DefaultUrlResolver is injected.
Is it even possible to override EPiServer UrlResolver?
I get an error message saying "Only concrete types can be built by ConstructorInstance"
Anyone done this?
/Jens