-
Notifications
You must be signed in to change notification settings - Fork 318
Mixing open generic and closed types for IEnumerable<T> #500
Comments
Just curious; for StructureMap (or all of them, for that matter), what happens if you register the closed type after the open type? |
Sorry for the late reply - here is the results of changing order:
|
@Antaris Does that mean it now returned a different type? The API might not be the most intuitive, but I think you might be using SM wrong. I think the registration should be something like var container = new StructureMap.Container(c =>
{
c.For(typeof(IHandler<,>)).Add(typeof(OpenHandler<,>));
c.For(typeof(IHandler<,>)).Use(typeof(ClosedHandler)); // Special case for string and int
});
var handlers = container.GetAllInstances<IHandler<string, int>>().ToArray(); // string and int returns 2
var otherHandlers = container.GetAllInstances<IHandler<string, double>>().ToArray(); // string and double returns 1 Take a look at Use vs Add 😄 This isn't very relevant to the original issue though 😝 |
@khellang You're right, by making that change, StructureMap behaves like the other containers (with the exception of Ninject which returned them in a different order). Edit: Almost the same - SM seems to always return the open types first, which is the opposite of Ninject, which always seems to return the closed types first. I know there are discussions around preserving order of registered types which is a far reaching issue. You're also right, this doesn't solve the root issue ;-) |
@pakrym - Done/Close? Or more work needed? |
We reverted previous fix, new PR #533 |
Hi Team,
I'm having trouble getting a particular scenario to work. I want to resolve all instances of a closed generic type, where the registrations may contain both concrete and open registrations:
When I try and resolve all instances of
IHandler<string, int>
, only the concrete implementation is returned:I thought I'd test other containers to see what they do:
Here is my project file:
In all but
Microsoft.Extensions.DependencyInjection
and StructureMap, all other contains return both instances.What would your recommendation be to achieve this? Is this functionality missing?
The text was updated successfully, but these errors were encountered: