I am a newbie in C #, and just started to learn IoC in web api.
What is the difference in Transient
and PerWebRequest
lifestyles
Sorry for bad English.
I am a newbie in C #, and just started to learn IoC in web api.
What is the difference in Transient
and PerWebRequest
lifestyles
Sorry for bad English.
It's mean "one instance for all". All times when you call Resolve
(even implicitly) you got the same object
It's opposite to singletone
. You'll get as many object as you call Resolve
Read how Singleton
for one request and transient
for other (You'll get as many object as request receive)
for more information read the catle.windsor manual or official asp.net docs
PerWebRequest scope lasts from the beginnning of a webcall to the end of the webcall. Transient lives as long as you hold a reference to the resolved entity. The AddTransient method is used to map abstract types to concrete services that are instantiated separately for every object that requires it.
Refer: Asp.Net Dependency Injection
Transient means you have as many objects as you called Ioc container. It also means you have to dispose all IDisposable items you created.
PerWebRequest means you will have 1 instance for every request, so if you have multiple requests running on server, each one will have its own object instance. IDisposable objects may be disposed by IoC framework.