-
Notifications
You must be signed in to change notification settings - Fork 14
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
EnableCurrentScope option gets overwritten #193
Comments
@seesharper, could you please give an advice? |
Hi @kemsky The reason that LightInject disables the "current scope" is because the default DI provider does not support this either. Instead it relies on passing the scope rather than storing the current scope in an On a side note. If you are migrating your apps you should really go for |
@seesharper, I wish I could migrate to net6.0, but it is almost impossible to update all our dependencies at once within limited timeframe (as always), so I started with the easiest possible way. I'm not sure if it is worth creating sample repo at this stage, I'll try to describe my problem better first. We use LightInject interception package a lot, for example: // Transactional attribute is a marker for async interceptor
[Transactional]
public virtual Task SaveAsync(Entity entity)
{
// this is just for illustration purposes, code executed inside transaction
await Context.SaveAsync();
} Async interceptor simply calls By now I've implemented custom Thanks in advance. |
Hi again @kemsky . I understand your concern about moving all the way to net6, but I would at least recommend that you move to netcoreapp3.1. Then you can go live with a runtime that is supported by Microsoft :) Regarding the scope problem you're having. It is not that I don't want to help you, but I have spent so much time in the past trying to guess what the actual scenario is :) . I don't have any experience with Entity Framework either so too many unknowns :) I would really like to help you out, but that would require a simple repro of the problem. In this case I would guess a simple WebAPI app that uses. LightInject, LightInject.Interception and Entity Framework? |
@seesharper, alright, this is example project: https://github.com/kemsky/lightinject-aspnet-core |
@seesharper, hi, did you have a chance to look at it? |
Currently we are migrating legacy app to Asp.Net Core 2.2 as the first step, so we are using
LightInject.Microsoft.AspNetCore.Hosting
.There are several interceptors that access current scope, for example transaction interceptor that automatically starts DB transaction, within interceptor we want to get scoped instance of EF context:
Container.GetInstance<IContext>()
, it requires current scope to work. I've tried the following:But it turns out that
EnableCurrentScope
gets overwritten:Now I'm confused, was it intentional? Maybe we are doing something wrong?
Looks like this is the same issue as #87.I tried another overload:
It kinda works, but only for the first call, next times scopes are in incorrect order and it breaks.
Does LightInject support current scope/nested scopes in Asp.Net Core at all?
The text was updated successfully, but these errors were encountered: