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

RegisterSingleton behaves inconsistently. #1008

Open
dotnetjunkie opened this issue Oct 2, 2024 · 0 comments
Open

RegisterSingleton behaves inconsistently. #1008

dotnetjunkie opened this issue Oct 2, 2024 · 0 comments
Labels
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

Considering the following example:

container.Register(typeof(Foo<>)); // class Foo<T> { }
container.RegisterSingleton(typeof(Bar<>)); // class Bar<T> { }
// Class Consumer<T>(Foo<T> f, Bar<T> b) { }
container.Register<Consumer<int>>();
container.Verify();

Verification fails complaining that Bar<int> is not registered.

Reason for this is that the RegisterSingleton overload called is RegisterSingleton(Type openGenericServiceType, params Assembly[] assemblies), which means that the following call is made:

container.RegisterSingleton(openGenericServiceType: typeof(Bar<>), assemblies: new Assembly[0]);

This results in the assembly scanning of non-generic implementations of Bar<T> within zero assemblies.

This actually costed me 10 minutes to figure out what was going on. If this happens to me... it can happen to anyone.

@dotnetjunkie dotnetjunkie added this to the v5.6 milestone Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant