Skip to content
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

ASP.Net Core PerLogicalCallContextScopeManagerProvider Thread Safety #483

Closed
AlexFlat opened this issue May 2, 2019 · 2 comments
Closed

Comments

@AlexFlat
Copy link

AlexFlat commented May 2, 2019

Hi,
We are using LightInject and ASP .Net Core 2.1 and are using the PerLogicalCallContextScopeManagerProvider.
Recently we found that our PerRequestLifeTime scope was invoking multiple calls to our instance during the same HTTP request.
We changed the scope to the PerScopeLifetime and found the same code only invoked once per HTTP request.

So from a functional point of view this seems to be the correct solution, however we could not find any documentation on how the link is made between the HTTPRequest and the PerScopeLifetime.

In our code we are NOT explicitly calling the Container.BeginScope() however from all our testing we cannot disprove the threading model.

Can you confirm there are no thread/security issues that could cause the same object to be returned from a different HTTP request in this scenario that does not explicitly call the Container.BeginScope()?

@seesharper
Copy link
Owner

The PerRequestLifeTime returns a new instance per request. Not HttpRequest , but every time an instance is requested from the container. The name PerRequestLifeTime might not be the best name as it can cause confusion when used in web applications. So the PerScopeLifetime is the right lifetime here. The scope in a web application is started when the web request starts and ends when the web request ends. This is done automatically by the Asp.Net infrastructure.

@AlexFlat
Copy link
Author

AlexFlat commented May 2, 2019

Thanks for the quick reply and clarification of the usage of PerScopeLifetime.
Might be a good idea to mention something like this in the doco as we found it difficult to determine when the Scope is created in ASP .Net and also that we dont have to explicitly call BeginScope when running in ASP .Net.
Again many thanks and happy to close this one

@AlexFlat AlexFlat closed this as completed May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants