Skip to content

ObjectFactory<T> delegate should be covariant #101829

Closed
@alrz

Description

@alrz

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-Extensions-DependencyInjectionin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions