I have Content Finder (IContentFinder) for displaying product page. From that Content Finder I'm trying to access a service registered as scoped.
When I run the site this error is thrown:
An error occurred while starting the application.
AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: ProductPageContentFinder Lifetime: Singleton ImplementationType: ProductPageContentFinder': Cannot consume scoped service 'IShopItemHelperService' from singleton 'ProductPageContentFinder'.)
How can I acess Scoped services inside ContentFinder?
Just to add to this for anyone in the future. Singleton is the highest level, and you cannot go down. A scope is, in (most scenario's you will encounter) the scope of the web request. ASP.NET starts a new scope with every request and will close this scope when the request finishes. Within this scope you'll have the same instances as a service which are registered as scoped. A singleton will span all scopes, it is a single instance in the lifespan of your application. Therefore, you cannot access something scoped from a single instance, because there is no scope.
Using scoped service in a ContentFinder
I have Content Finder (IContentFinder) for displaying product page. From that Content Finder I'm trying to access a service registered as scoped.
When I run the site this error is thrown:
How can I acess Scoped services inside ContentFinder?
were you able to resolve this issue?
Instead of using Content Finde I used UmbracoPageController, with custom routing...
https://our.umbraco.com/documentation/implementation/Custom-Routing/#custom-mvc-routes
Inside your UmbracoPageController then you can access the Scoped services, contnet and everithing....
Hope it is helpfull, if you need more specific code let me know...
Just to add to this for anyone in the future. Singleton is the highest level, and you cannot go down. A scope is, in (most scenario's you will encounter) the scope of the web request. ASP.NET starts a new scope with every request and will close this scope when the request finishes. Within this scope you'll have the same instances as a service which are registered as scoped. A singleton will span all scopes, it is a single instance in the lifespan of your application. Therefore, you cannot access something scoped from a single instance, because there is no scope.
is working on a reply...