-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Application breaks after updating to v6.3.5+ (LightInject.Web.PerWebRequestScopeManager.GetOrAddScope()) #559
Comments
To add, I have confirmed on my end that the issue of multiple instances is caused by Override method. Even though I am passing PerContainerLifetime in the registration func, the objects are created numerous times. |
I tried to repro this in a new project, but couldn't. And the project it was happening in was too large to trim down to find a minimal repro. However I found another of our projects has the same issue in another way. This other project is net6.0, and uses .CreateServiceProvider() (in LightInject.Microsoft.DependencyInjection) to create the service provider and in an IHostedService I was able to find this scenario:
I was able to identify commit e803e57 as problematic, while commit daaf6a0 is ok by building both commits and copying over the lightinject.dll to our application. |
I tried removing the implementations of IHandler one by one. With 13 types it works, with 14 types it throws
I suspect we might have a problem somewhere with singleton types depending on transient or scoped types, but it will take some time to investigate whether this is true. |
@sirphilliptubell First of all, I really appreciate the time you have put into investigating this. If you could narrow this down into a working repro that would be great although I understand it might be difficult to do so. |
fyi, just realized I meant to reply to issue #561, not this one. Sorry to throw this thread off it's rails. I'll continue posting in the other thread. |
Hey, I have a .NET 472 mvc application running in production that uses LightInject and LightInject.Web packages. I have an internal package that is basically a wrapper around LightInject package.After updating to v6.3.5 or later, I started experiencing 2 different issues.
1 - My package did not pass Lifetime parameter for Override method. With the update, all of the registrations that were overriden started acting as transient - numerous instances of objects were created. I fixed this with passing Lifetime parameter into Override method (as part of the ServiceRegistration object that's returned from a func parameter).
2 - The application has numerous background services that are triggered on a timer. The application uses EnablePerWebRequestScope extension method to use PerWebRequestScopeManagerProvider.
I started getting these errors for all of the timer-driven services. After looking at the source code, I suspect the issue is that GetOrAddScope() function tries to access HttpContext.Current which will be null in this case. I have copied over the LightInject.Web.cs file and added a null check for HttpContext.Current. While this fixed my errors for background services, I started getting multiple instances of the services that have Override registrations.
Is this something you have encountered before?
The text was updated successfully, but these errors were encountered: