dadhi / DryIoc

DryIoc is fast, small, full-featured IoC Container for .NET
MIT License
988 stars 122 forks source link

Rules.WithFactorySelector(Rules.SelectLastRegisteredFactory()) allows to Resolve the keyed service as non-keyed #557

Closed dadhi closed 1 year ago

dadhi commented 1 year ago

The original case is here https://dotnetfiddle.net/HaV38I But it works as intended (does not resolve the keyed service without key) when WithFactorySelector is commented out.

            var rules = Rules.Default
                .WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient)
                .With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments))
                .WithFuncAndLazyWithoutRegistration()
                .WithTrackingDisposableTransients();
                // .WithFactorySelector(Rules.SelectLastRegisteredFactory()); // works when commented

            var c = new Container(rules);

            c.Register(typeof(IServiceA), typeof(ServiceA), Reuse.Transient, ifAlreadyRegistered: IfAlreadyRegistered.Replace, serviceKey: "Test");

            var serviceA = c.Resolve<IServiceA>(IfUnresolved.ReturnDefault);
            Assert.IsNull(serviceA);