0
votes

Is there a mechanism in the dependency injector in OpenRasta that tears down the instance of an object that is created? Regardless the dependency lifetime.

I tried looking through the source, but could not directly find any tear down. Nor seems implementing IDisposable do the trick.

Update I was mainly looking for disposing a singleton, so I won't be opening a ticket on the openrasta-core project. For the moment I keep track of the instance of the singleton in my own library (currently not knowing how to access singletons in OpenRasta directly), to access upon application close.

1

1 Answers

2
votes

Disposing is a whole bag of pain to implement right. Per-request objects have a known object lifetime (containers that implement the OR DI interface have a hook to know when to dispose that scope), statics (since 2.1.1) will be disposed by the container on shutdown of the host (which means nearly never for asp.net, and whenever you close the self-hosted server / in mem hosting), and transients we have no clue how to do it: how do you know when something has to be disposed if you don't keep track of it, which if you do means that it doesn't get released, it's all very problematic.

So the internal DI container doesn't dispose anything at all, although we may add the disposing of singletons on container dispose and of per-request on request shutdown, I suppose that'd be quite useful. Feel free to add a github ticket on the openrasta-core project.

Alternatively, use an existing IoC container in place of the existing one. Some people have also added custom contributors to do the cleanup themselves without having to use an external container.

Seb