You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;using LightInject;using LightInject.Microsoft.DependencyInjection;namespaceLightInjectRepro{publicinterfaceIFoo{}namespaceOne{publicclassFoo:IFoo{}}namespaceTwo{publicclassFoo:IFoo{}}internalclassProgram{staticvoidMain(string[]args){if(args.Length !=1){thrownew ArgumentException("Only only arg is permitted: e.g. \"LightInjectRepro.exe One\"");}varoptions=new ContainerOptions().WithMicrosoftSettings();varcontainer=new ServiceContainer(options);
container.Register<IFoo, One.Foo>("One.Foo");
container.Register<IFoo, Two.Foo>("Two.Foo");
container.Register<IFoo>(f =>{switch(args[0]){case"one":case"One":return f.GetInstance<IFoo>("One.Foo");case"two":case"Two":return f.GetInstance<IFoo>("Two.Foo");default:thrownew ArgumentException($"Invalid cli parameter: {args[0]} (only One or Two are valid values)");}});varfoo= container.GetInstance<IFoo>();return;}}}
The code above runs but container.GetInstance<IFoo>();always returns an instance of Two.Foo. The f => {} third registration doesn't kick in.
The container.AvailableServices enumerable does contain the three services that have been registered.
Downgrading to <PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.6.3" /> changes the behaviour back to how it worked in the past and the callback runs and you get the either and instance of One.Foo or Two.Foo depending on your cli parameter.
Hello,
We have just noticed something odd after updating to
LightInject.Microsoft.DependencyInjection
fromv3.6.3
tov3.7.1
(v3.7.0 is also affected):Steps to reproduce
Create a new CLI project:
Program
The code above runs but
container.GetInstance<IFoo>();
always returns an instance ofTwo.Foo
. Thef => {}
third registration doesn't kick in.The
container.AvailableServices
enumerable does contain the three services that have been registered.Downgrading to
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.6.3" />
changes the behaviour back to how it worked in the past and the callback runs and you get the either and instance ofOne.Foo
orTwo.Foo
depending on your cli parameter.Could this be a consequence of that change?
The text was updated successfully, but these errors were encountered: