-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Feature Request] Generic ObjectFactory and ActivatorUtilities.CreateFactory #34471
Comments
As described in aspnet/Announcements#411, this code has moved to dotnet/runtime (https://github.com/dotnet/runtime/blob/master/src/libraries/Common/src/Extensions/ActivatorUtilities/ActivatorUtilities.cs). Transferring this issue there. |
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
cc @ericstj |
Related: #36194 |
Seems like a straightforward API addition. Set it up as |
namespace Microsoft.Extensions.DependencyInjection
{
public delegate T ObjectFactory<T>(IServiceProvider serviceProvider, object?[]? arguments);
public static partial class ActivatorUtilities
{
public static ObjectFactory<T> CreateFactory<T>(Type[] argumentTypes) { throw null; }
}
} |
Related: #36194, though the scenario is a bit different, so there's room for both sets of APIs. I could easily see DI-specific functionality being written atop a generalized reflection factory API as value add. |
Is your feature request related to a problem? Please describe.
Currently when I want to use
ObjectFactory
created byActivatorUtilities.CreateFactory
I have to use explicit cast to destination type for the result ofObjectFactory
's invocation.Describe the solution you'd like
I think that it would be better to add a method to
ActivatorUtilities
with following signatureObjectFactory<T> CreateFactory<T>(Type[] argumentTypes)
that allows to avoid explicit casts.API Proposal
namespace Microsoft.Extensions.DependencyInjection { public static partial class ActivatorUtilities { public static ObjectFactory CreateFactory(Type instanceType, Type[] argumentTypes) { throw null; } + public static ObjectFactory<T> CreateFactory<T>(Type[] argumentTypes) { throw null; } public static object CreateInstance(IServiceProvider provider, Type instanceType, params object[] parameters) { throw null; } public static T CreateInstance<T>(IServiceProvider provider, params object[] parameters) { throw null; } } }
The text was updated successfully, but these errors were encountered: