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

Improve "The supplied list of types contains one or multiple open-generic types, but this method is unable to handle open-generic types" message #719

Open
dotnetjunkie opened this issue May 20, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@dotnetjunkie
Copy link
Collaborator

commented May 20, 2019

When the Register(Type, IEnumerable<Type>) or Register(Type, IEnumerable<Type>, Lifestyle) overloads are supplied with a list of types that contains one or more open-generic types, these methods throw the following exception:

The supplied list of types contains one or multiple open-generic types, but this method is unable to handle open-generic types because it can only map closed-generic service types to a single implementation. You must register the open-generic types separately using the Register(Type, Type) overload. Alternatively, try using Container.Collection.Register instead, if you expect to have multiple implementations per closed-generic abstraction. Invalid types: {0}

There is room for improvement here:

  • An example can be given of a correct mapping that is presented
  • The message can be more exact whether there is one or more open-generic types supplied
  • The message can be more exact on when you use Collection.Register

Here's an improved version of the message:

The supplied list of types contains an open-generic type, but this method is unable to handle open-generic types—it can only map closed-generic service types to a single implementation. As an example, the supplied OrderCanceledHandler can be used as implementation for the closed-generic service type IHandler<OrderCanceled>, because OrderCanceledHandler does not contain any generic type arguments. You must register the open-generic type separately using the Register(Type, Type) overload. Alternatively, try using Container.Collection.Register instead, if you expect to have multiple implementations per closed-generic service type and want to inject a collection into consumers. Invalid type: RegisterBatchTests.GenericHandler.

@dotnetjunkie dotnetjunkie added this to the v4.7 milestone May 20, 2019

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