Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bor 12 posts 125 karma points
    Dec 21, 2021 @ 14:53
    Bor
    0

    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:

    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?

  • Dee 118 posts 338 karma points
    Oct 09, 2022 @ 17:07
    Dee
    0

    were you able to resolve this issue?

  • Bor 12 posts 125 karma points
    Oct 10, 2022 @ 08:34
    Bor
    1

    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...

  • Roy Berris 89 posts 577 karma points c-trib
    Oct 10, 2022 @ 13:43
    Roy Berris
    3

    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.

Please Sign in or register to post replies

Write your reply to:

Draft