Skip to content
This repository was archived by the owner on Nov 2, 2018. It is now read-only.
This repository was archived by the owner on Nov 2, 2018. It is now read-only.

Support instance and factory ServiceDescriptors with TryAddEnumerable  #262

@mikary

Description

@mikary

TryAddEnumerable only supported adding services that were registered as a type, the same functionality is useful with other registration patterns.

TryAddEnumerable does not have an overload that takes an IEnumerable<ServiceDescriptor>, such an overload is useful for some registration patterns and would give better parity with the TryAdd methods.

The factory add methods (i.e. AddSingleton<TService>( IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)) allow for inline lambda definitions, but service descriptors for two different implementation types end up being indistinguishable from each other, preventing TryAddEnumerable from properly determining if a service should be added. New factory methods with explicit implementation types (i.e. AddSingleton<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory)) would provide convenience for these registration patterns.

The return types of the TryAdd and TryAddEnumerable methods are generally not used (the functionality is generally used as an "Add if not defined") Aditional API cleanup may be required to clarify the intended use of these methods.

The generic type constraints are inconsistent for the registration methods, service and implementation types should be reference types (T : class) and implementation types should be derived from the service type (TImplementation : TService).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions