Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve with serviceKey doesn't invoke factory selector #667

Open
cnshenj opened this issue Nov 13, 2024 · 3 comments
Open

Resolve with serviceKey doesn't invoke factory selector #667

cnshenj opened this issue Nov 13, 2024 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@cnshenj
Copy link

cnshenj commented Nov 13, 2024

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;
};
@dadhi
Copy link
Owner

dadhi commented Nov 14, 2024

@cnshenj Huh, ok. Will check.

dadhi added a commit that referenced this issue Nov 14, 2024
@dadhi
Copy link
Owner

dadhi commented Nov 14, 2024

Seems reproducible. Thanks

@dadhi dadhi self-assigned this Nov 14, 2024
@dadhi dadhi added the bug Something isn't working label Nov 14, 2024
@dadhi dadhi added this to the v6.0.0 milestone Nov 14, 2024
@dadhi
Copy link
Owner

dadhi commented Nov 14, 2024

@cnshenj Actually, the FactorySelector was introduced to select the factory from multiple registrations without key.
Because by definition, at least in my mind, when you are providing the key, it is supposed to uniquely identify the registration.
Therefore, you did the selection of factory on your end.

But... sigh, currently we have the MS.DI keyed services where the keys can be the same for the save service type. So the keys are operating like the labels, or metadata which is supported by DryIoc and is a separate feature.

Given the current need of integration with MS.DI, let's keep this issue open and I will work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants