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

ObjectFactory<T> delegate should be covariant #101829

Open
alrz opened this issue May 3, 2024 · 5 comments · May be fixed by #102553
Open

ObjectFactory<T> delegate should be covariant #101829

alrz opened this issue May 3, 2024 · 5 comments · May be fixed by #102553
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-Extensions-DependencyInjection
Milestone

Comments

@alrz
Copy link

alrz commented May 3, 2024

Current workaround is to use the non-generic ObjectFactory and cast but that shouldn't be necessary.

ObjectFactory<A> a = ...;
ObjectFactory<B> b = ...;
ObjectFactory<Base> f = c ? a : b;
return f(...);

API Proposal

namespace Microsoft.Extensions.DependencyInjection;
- public delegate T ObjectFactory<T>(IServiceProvider serviceProvider, object?[]? arguments);
+ public delegate T ObjectFactory<out T>(IServiceProvider serviceProvider, object?[]? arguments);
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 3, 2024
Copy link
Contributor

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

@stephentoub stephentoub added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed untriaged New issue has not been triaged by the area owner labels May 3, 2024
@stephentoub
Copy link
Member

public delegate T ObjectFactory<T>(IServiceProvider serviceProvider, object?[]? arguments);

@stephentoub stephentoub added this to the 9.0.0 milestone May 5, 2024
@alrz
Copy link
Author

alrz commented May 5, 2024

Would it be possible to use params ReadOnlySpan<object> for the arguments here?
(I suppose this would be considered as a part of new params span set of APIs though.)

@stephentoub
Copy link
Member

Would it be possible to use params ReadOnlySpan<object> for the arguments here? (I suppose this would be considered as a part of new params span set of APIs though.)

That would need to be an entirely different delegate and an entirely different set of APIs that take that delegate... just changing the delegate itself would be a binary breaking change. Feel free to open a separate issue with such a proposal.

@alrz
Copy link
Author

alrz commented May 5, 2024

Opened #101889

alrz added a commit to alrz/runtime that referenced this issue May 22, 2024
@alrz alrz linked a pull request May 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-Extensions-DependencyInjection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants