There are some classes that don't work out of the box for DI, one of those is MVC so WebAPI and Controllers have issues. Is this your first use in a controller injecting or is it only happening when adding the new service? This will help me gauge if this is isolated to the one service.
If it's working without it you need to make sure the service registered for the IContentResolver is set up either in your service setup class or wrapping the class that inherits it in the service attribute.
https://world.episerver.com/documentation/developer-guides/CMS/initialization/dependency-injection/
ITs the first use in my controller using the IContentResolver service... all the other work without problems. But when i add this one, it fails.
How would i register the IContentResolver in Structuremap.
The link was at the bottom of my previous post https://world.episerver.com/documentation/developer-guides/CMS/initialization/dependency-injection/
With the last few versions it's finding your InitializationModule responsible for registering the services in your solution and adding
context.Services.AddTransient<IService, Service>();
Where IService is IContentResolver and Service is whatever implementation you have set up.
I dont have any specific IContentResolver service setup...
i just want an instance of it.. So i can use its methods..
var resolver = ServiceLocator.Current.GetInstance<IContentResolver>();
IContentResolver being an Episerver interfaces you'd usually expect there to be one already configured in it's internal implementation so this is only needed if you've changed the implementation or if for some reason there's no default IContentResolver implementation. If you're unsure I'd suggest checking the assmblies with a decompiler such as DotPeek or ILSpy
It should be using DefaultContentProvider in the EPiServer.Core.Internal namespace of Episerver.
I'd try re-forcing this using
context.Services.AddTransient<IContentResolver, DefaultContentProvider>();
As it may be a structuremap issue. If this doesn't work I'd raise it as a bug with Episerver, if you're sure all your resolver bits are configured.
I don't think this interface is in use anymore.
It says: "Interface used by PermanentLinkMapStore to resolve a content instance from an identity".
PermanentLinkMapStore
is marked as obsolete.
The default implementation of IPermanentLinkMapper
is EPiServer.Web.Internal.PermanentLinkMapper
which doesn't have any dependencies to IContentResolver
.
Thanks Scott and Dejan..
i tried PermanentLinkMapper, but also Scotts way works..
thanks guys.
Hi Guys,
in one of my controller i try to inject IContenResolver. Example..All the other DI's services work, but the IContentResolver doesnt.
But get the error:
No default Instance is registered and cannot be automatically determined for type 'EPiServer.Web.IContentResolver'
There is no configuration specified for EPiServer.Web.IContentResolver
1.) Container.GetInstance(EPiServer.Web.IContentResolver)
Even if i just try the ServiceLocation way, i get the same.. what am i missing?