Skip to content

Resolve with serviceKey doesn't invoke factory selector #667

@cnshenj

Description

@cnshenj

It can be reproed using DryIoc 5.4.3

new Container(
    rules =>
        rules.WithFactorySelector(
            (request, single, many) =>
            {
                // Do something here
            }));

container.Register<IFoo, Foo>(); // Default
container.Register<IFoo, Foo>("my"); // Keyed
container.Resolve<IFoo>(); // Custom factory selector invoked
container.Resolve<IFoo>("my"); // Custom factory selector NOT invoked

Slightly related, I don't like returning null to tell DryIoc to use the default factory. It's not obvious, and prevents a useful pattern like this:

// Rules.Default.FactorySelector is null so it can't be really used
var defaultFactory = Rules.Default.FactorySelector(request, single, many);
if (IsSpecialType(defaultFactory.ImplementationType))
{
    // Return a different factory
}
else
{
    return defaultFactory;
};

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions