Skip to content
This repository has been archived by the owner on Mar 2, 2023. It is now read-only.

UnityPerRequestHttpModule is disposing instances with container controlled lifetime #19

Open
ArnaudB88 opened this issue Apr 16, 2021 · 0 comments
Labels
Requires Investigation 👮 Requires further verification

Comments

@ArnaudB88
Copy link

Hi, I recently found a bug where my singleton instance (logger) is disposed at the beginning of my MVC web application.
On the first 'end request' event of the web application, the logger is disposed. Looking at the call stack, it seems the UnityPerRequestHttpModule.OnEndRequest() disposes all items on the context. The item list contains the container controlled instance of my logger.

Some code:
In the container registrations I have:
container.RegisterSingleton<Common.Interfaces.ILogger, SerilogLogger>();

I added an 'Application_EndRequest()' method on the global.asax class of my web application, simply showing me all registered items in the HTTPContext. A screenshot proving that the singleton instance is present in that items list (3th item):
image

That same list is processed by the UnityPerRequestHttpModule.OnEndRequest().
Only instances with the PerRequestLTM should be disposed I guess.

Important note: this issue only appears when the singleton logger is needed by a PerRequest registered class and first resolved for that class. When the singleton logger is already resolved before needed by a PerRequest registered class, this issue doesn't appear. The items list (screenshot above) is the same, except the logger instance is missing in that list.

@ENikS ENikS added the Requires Investigation 👮 Requires further verification label Apr 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Requires Investigation 👮 Requires further verification
Projects
None yet
Development

No branches or pull requests

2 participants