Let’s say I have some dependencies registered in a container.
container.AddSingleton<IMySingleton, MySingleton>(); container.AddTransient<IMyTransient, MyTransient>();
and let’s say that
MyTransient are both
ServiceStack should do the right thing for me at either the end of the HTTP Request, or at the end of the service lifetime and dispose the registered instances. All good there.
Now, if somewhere in the service, or filters, or elsewhere I do something like:
var instance = IRequest.Resolve<IMySingleton>();
OR perhaps in my AppHost:
var instance = container.Resolve<IMySingleton>();
Then I understand that I am responsible for calling
Dispose(); in the returned instance.
Isn’t that correct?
If so, then what actually happens if I call
instance.Dispose() on the IMySingleton instance? Does that mean that the singleton itself will be disposed, and will be disposed if it is injected elsewhere by ServiceStack?
Seems like I will need to know if it is a singleton or transient to know whether to dispose the instance or not. And not dispose the singleton that are already registered in the container. Is that correct?
How do I tell if it is registered as a singleton or as a transient in the container?