30 April 2024

When to use which Service, Singleton, Scoped and Transient

 

When to use which Service, Singleton, Scoped and Transient

Singleton approach => We can use this for logging service, feature flag (to on and off module while deployment), and email service,

Scoped approach => This is a better option when you want to maintain a state within a request,

Transient approach =>  Use this approach for the lightweight service with little or no state.

Scoped Approach in detail
The same instance lives for the entire scope of that request, for example; let's suppose one controller has two parameters, both are the objects of the same "Sample" class, then both the objects will share the same instance across the request,

No comments:

Post a Comment

Comments Welcome

Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...