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

Explain that collections need to be registered explicitly #441

Closed
dotnetjunkie opened this issue Jul 20, 2017 · 1 comment
Closed

Explain that collections need to be registered explicitly #441

dotnetjunkie opened this issue Jul 20, 2017 · 1 comment
Labels
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

@dotnetjunkie dotnetjunkie commented Jul 20, 2017

The following code:

var container = new Container();
container.RegisterInstance(new object()); // to ensure the container isn't empty
container.GetAllInstances<IPlugin>(); // resolve an unregistered collection

Fails with the following exception message:

No registration for type IEnumerable<IPlugin> could be found.

It fails to mention that Simple Injector requires collections to be registered explicitly, even though there are no services to register. Not mentioning this can be quite confusing to the user, especially when he expects to get an empty collection.

Expected message:

No registration for type IEnumerable<IPlugin> could be found. You can use one of the Container.Collection.Register overloads to register a collection of IPlugin types, or one of the Container.Collection.Append overloads to append a single registration to a collection. In case you intend to resolve an empty collection of IPlugin elements, make sure you register an empty collection; Simple Injector requires a call to Container.Collection.Register to be made, even in the absence of any instances. Please see https://simpleinjector.org/collections for more information about registering and resolving collections.

@dotnetjunkie dotnetjunkie added this to the v4.8 milestone Sep 20, 2019
@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Sep 20, 2019

bug-441 branch created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.