IServiceCollection Access

Hanaa Gebril 1 Reputation point
2021-02-19T20:39:56.237+00:00

How can I access IServiceCollection from web api or controller?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
2,599 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lohith GN 501 Reputation points
    2021-04-09T05:21:28.907+00:00

    @Hanaa Gebril

    Not sure what you are trying to achieve. You will need to provide more explanation on your question.

    The concept of IServiceCollection is - its a container which is built up at the start of your app. You register components with the collection with lifetime specified (Singleton, Scoped etc). Once your app starts and container is built with all your dependent components, you just ask for the component you need through your constructor dependency. ASP.NET Core makes sure that whatever dependency a class is asking for will be picked up from your container and provided to the class. Thats DI & IoC principle in play...

    So when you say i want to access IServiceCollection - what for ?

    No comments