Dependency Injecting IContentResolver error - No default Instance registered

Vote:
 

Hi Guys,

in one of my controller i try to inject IContenResolver. Example..All the other DI's services work, but the IContentResolver doesnt. 

 public class OrphanedBlocksReportController : Controller
    {
        private readonly IContentTypeRepository contentTypeRepository;
        private readonly IAdministrationSettingsService administrationSettingsService;
        private readonly ContentTypeAvailabilityService contentTypeAvailabilityService;
        private readonly ModuleTable moduleTable;
        private readonly ServiceAccessor<SiteDefinition> currentSiteDefinition;
        private readonly ContentTypeModelRepository contentTypeModelRepository;
        private readonly IContentModelUsage contentModelUsage;
        private readonly IContentRepository repository;
        private readonly IContentSoftLinkRepository linkRepository;
        private readonly IContentResolver resolver;

        public OrphanedBlocksReportController(IContentTypeRepository contentTypeRepository, IAdministrationSettingsService administrationSettingsService,
                                                    ContentTypeAvailabilityService contentTypeAvailabilityService,
                                                    ModuleTable moduleTable,
                                                    ServiceAccessor<SiteDefinition> currentSiteDefinition,
                                                    ContentTypeModelRepository contentTypeModelRepository,
                                                    IContentModelUsage contentModelUsage,
                                                    IContentRepository repository,
                                                    IContentSoftLinkRepository linkRepository,
                                                    IContentResolver resolver)
        {
            this.contentTypeRepository = contentTypeRepository;
            this.administrationSettingsService = administrationSettingsService;
            this.contentTypeAvailabilityService = contentTypeAvailabilityService;
            this.moduleTable = moduleTable;
            this.currentSiteDefinition = currentSiteDefinition;
            this.contentTypeModelRepository = contentTypeModelRepository;
            this.contentModelUsage = contentModelUsage;
            this.repository = repository;
            this.linkRepository = linkRepository;
            this.resolver = resolver;
            
        }
}

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?

var contentResourceFolder = repository.GetDefault<ContentAssetFolder>(block.ParentLink);
                        var guid = contentResourceFolder.ContentOwnerID;
                        var resolver = ServiceLocator.Current.GetInstance<IContentResolver>();                        
                        var ref4 = resolver.ResolveContent(guid);

#201112
Feb 06, 2019 10:21
Vote:
 

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/

#201122
Feb 06, 2019 13:01
Vote:
 

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.

#201125
Edited, Feb 06, 2019 13:18
Vote:
 

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.

#201126
Feb 06, 2019 13:35
Vote:
 

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>(); 

#201127
Feb 06, 2019 13:37
Vote:
 

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

#201128
Feb 06, 2019 13:37
Vote:
 

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.

#201130
Edited, Feb 06, 2019 13:52
Vote:
 

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.

#201131
Feb 06, 2019 13:58
Vote:
 

Thanks Scott and Dejan..

i tried PermanentLinkMapper, but also Scotts way works.. 

thanks guys. 

#201132
Feb 06, 2019 14:03
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.