Dependency Injection Options

By | December 19, 2018

Transient
Shortest lifespan : An instance will be created every time one is requested.

Each request an instance of given class,the framework will give them each their own instance and not share anything between them

 

Scoped
A single instance will be created for each “scope”.In ASP.NET Core MVC,the “scope” is almost always the current web request

This approach allows to share state between different components throughput the same request without worrying about  another user’s request gaining access the same data

 

Singleton
A singleton instance will be created for the entire application.This method will only create  one instance of each type for the entire lifetime of the application which is helpful in cases when you have some common data that you want to share across all users or when you have a type that’s particularly  expensive  to create and is not specific to any particular user or request

One thought on “Dependency Injection Options

Leave a Reply

Your email address will not be published. Required fields are marked *