Skip to content

Files

Latest commit

4eeeeca · Feb 27, 2024

History

History

dependency-injection-2

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Nov 29, 2021
Nov 11, 2020
Feb 27, 2024

IServiceProvider

IServiceProvider is a service locator. It allows you to obtain objects from the dependency injection system. It is considered a bad practice in common scenario.

It is better to be explicit of your dependency in your constructor e.g. MyObject(ILogger<MyObject> logger, IStringLocalizer<MyObject>) than using MyObject(IServiceProvider provider) and obtain those objects via the provider.

However when you encounter a situation where using a service locator is needed, IServiceProvider is there for you.