Allow Register an open-generic service type with closed implementation to enable variance

Issue #554 resolved
Maksim Volkau
repo owner created an issue

See SO question and my answer for the context.

Comments (5)

  1. Maksim Volkau reporter

    I have decided to go with Resolve only. It will allow to do Register(typeof(IBlah<>), typeof(Blah)). Yep. it may blow up later on Resolve when the type arguments are not matched to constraints. But you are agree on this when registering the open-generic service type.

    The reason to not do that for RegisterMany is the breaking change. I have a 4 tests immediately breaking when I've changed the behavior.

    The actual change here is that ResolveMany will return 2 services, one for closed and the one for open-generic registration. If we exclude closed-generic, it feels wrong, as it is a concrete (preferred) service type implemented.

    The possible solution is opt-in the specific registration, but it is not different from excluding or overriding the specific registration with Register an open-generic service type.

  2. Log in to comment