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

[API Proposal]: ActivatorUtilities.CreateFactoryOf<TDelegate> #111228

Open
alrz opened this issue Jan 9, 2025 · 2 comments
Open

[API Proposal]: ActivatorUtilities.CreateFactoryOf<TDelegate> #111228

alrz opened this issue Jan 9, 2025 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Extensions-DependencyInjection untriaged New issue has not been triaged by the area owner

Comments

@alrz
Copy link
Member

alrz commented Jan 9, 2025

Background and motivation

As an alternative to #101889 this API would be only exposed as a single method taking the delegate as a type arg. This will avoid array allocation and boxing for the args, and also typechecks that the callsite matches the factory.

API Proposal

namespace Microsoft.Extensions.DependencyInjection
{
  public static class ActivatorUtilities
  {
+    public static T CreateFactoryOf<T>() where T : Delegate;
  }
}

API Usage

// IServiceProvider is specially recognized
var f1 = ActivatorUtilities.CreateFactoryOf<Func<IServiceProvider, TArg, TResult>>();
// but it's optional when not using DI
var f2 = ActivatorUtilities.CreateFactoryOf<Func<TArg, TResult>>(); 
// Just like Lambda<T> you could choose to use a custom delegate type
var f3 = ActivatorUtilities.CreateFactoryOf<CustomDelegate>();

Alternative Designs

No response

Risks

No response

@alrz alrz added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 9, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 9, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

@MichalPetryka
Copy link
Contributor

I assume this will be rejected for same reasons as #36194.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Extensions-DependencyInjection untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants