Skip to content

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

@dadhi

Description

@dadhi

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);

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions