Singleton or Transient is suitable for large website application

Currently working on a large website just I need a recommendation about Singleton or Transient which one is suitable I should use? thank you.

[AddSingleton]

method which means even if we insert service or repository in 2 places Controller and View it will create only one instance of that repository.

So in AddSingleton method, only one instance is created and which is served all Http/https requests throughout the application.

[AddTransient]

In this method every time the new instance will be created for every request like scoped method but if method call is in the scope then also new service object will be created.

Means whether it is same scope on same Http call or different Http call or request every time it will create different object.

As per your application requirement choose which one you want to use.

1 Like
.NET Foundation Website | Blog | Projects | Code of Conduct