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

[Feature Request] Generic ObjectFactory and ActivatorUtilities.CreateFactory #34471

Closed
Tracked by #77390
TechnoBerry opened this issue Mar 31, 2020 · 7 comments · Fixed by #77185
Closed
Tracked by #77390

[Feature Request] Generic ObjectFactory and ActivatorUtilities.CreateFactory #34471

TechnoBerry opened this issue Mar 31, 2020 · 7 comments · Fixed by #77185
Labels
api-approved API was approved in API review, it can be implemented area-Extensions-DependencyInjection
Milestone

Comments

@TechnoBerry
Copy link

TechnoBerry commented Mar 31, 2020

Is your feature request related to a problem? Please describe.

Currently when I want to use ObjectFactory created by ActivatorUtilities.CreateFactory I have to use explicit cast to destination type for the result of ObjectFactory's invocation.

Describe the solution you'd like

I think that it would be better to add a method to ActivatorUtilities with following signature ObjectFactory<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; }
    }
}
@TechnoBerry TechnoBerry changed the title Generic ObjectFactory and ActivatorUtilities.CreateFactory [Feature Request] Generic ObjectFactory and ActivatorUtilities.CreateFactory Mar 31, 2020
@analogrelay
Copy link
Contributor

@analogrelay analogrelay transferred this issue from dotnet/extensions Apr 2, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Apr 2, 2020
@analogrelay
Copy link
Contributor

cc @ericstj

@GrabYourPitchforks
Copy link
Member

Related: #36194

@eerhardt eerhardt added api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed untriaged New issue has not been triaged by the area owner labels Jul 7, 2020
@eerhardt eerhardt added this to the Future milestone Jul 7, 2020
@maryamariyan maryamariyan added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Oct 13, 2022
@maryamariyan
Copy link
Member

maryamariyan commented Oct 13, 2022

Seems like a straightforward API addition. Set it up as api-ready-for-review. This might also help with linkability.

@bartonjs
Copy link
Member

bartonjs commented Oct 18, 2022

Video

  • Consider, in the future, adding more generic overloads that avoid the Type[] and object?[]? elements for pre-known signatures. These would probably use Func instead of new generic arities of ObjectFactory
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; }
    }
}

@bartonjs bartonjs added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Oct 18, 2022
@maryamariyan maryamariyan modified the milestones: Future, 8.0.0 Oct 18, 2022
@GrabYourPitchforks
Copy link
Member

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.

maryamariyan added a commit to maryamariyan/runtime that referenced this issue Oct 18, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 18, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Oct 20, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-Extensions-DependencyInjection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants