-
Notifications
You must be signed in to change notification settings - Fork 14
Description
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:
public static IWebHost CreateWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseLightInject(options =>
{
options.EnableCurrentScope = true;
})
.UseStartup<Startup>()
.Build();But it turns out that EnableCurrentScope gets overwritten:
public LightInjectServiceProviderFactory(ContainerOptions options)
{
var clonedOptions = options.Clone();
clonedOptions.WithMicrosoftSettings(); // <--- Here!
containerFactory = () => new ServiceContainer(clonedOptions);
}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:
.UseLightInject(new ServiceContainer(new ContainerOptions
{
EnableVariance = false,
EnableCurrentScope = true,
EnableOptionalArguments = true,
EnablePropertyInjection = false
}))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?