aspnet / DependencyInjection

[Archived] Contains common DI abstractions that ASP.NET Core and Entity Framework Core use. Project moved to https://github.com/aspnet/Extensions
Apache License 2.0
872 stars 318 forks source link

Consider lifting requirement to register open generic types by type #450

Closed khellang closed 8 years ago

khellang commented 8 years ago

When working on decoration in Scrutor, I noticed that there's an exception being thrown if you try to register an open generic type using a factory function.

What's the reasoning behind this? Is it just an oversight?

They way I've implemented the decoration is by chaining together ServiceDescriptors using a combination of factory functions and ActivatorUtilities, but by having this limitation in place, I can't register a factory function for open generics.

It would be nice if this requirement was lifted :smile:

khellang commented 8 years ago

Actually, after doing this work myself and digging a bit deeper, I realized this won't work anyway, cause there's no way to know the actual type being requested in a factory function.

That means I can't get the generic arguments of the concrete service type being requested :disappointed:

I don't see a way this can be solved, without changing the signature of the factory delegate to include more information...