Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class Microsoft.​Extensions.​DependencyInjection.​Extensions.​ServiceCollectionDescriptorExtensions
Assembly: Microsoft.Extensions.DependencyInjection.Abstractions
Inheritance: object → ServiceCollectionDescriptorExtensions
Extension methods for adding and removing services to an <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
Methods
public static
IServiceCollection
Add​(IServiceCollection collection,
ServiceDescriptor descriptor)
Adds the specified <paramref name="descriptor" /> to the <paramref name="collection" /> .
Returns A reference to the current instance of <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
descriptor
The <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> to add.
public static
IServiceCollection
Add​(IServiceCollection collection,
System.​Collections.​Generic.​IEnumerable<​ServiceDescriptor> descriptors)
Adds a sequence of <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> to the <paramref name="collection" /> .
Returns A reference to the current instance of <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
descriptors
The <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> s to add.
public static
IServiceCollection
RemoveAll​(IServiceCollection collection,
System.​Type serviceType)
Removes all services of type <paramref name="serviceType" /> in <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
Returns The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> for chaining.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceType
The service type to remove.
public static
IServiceCollection
RemoveAll​(IServiceCollection collection)
Removes all services of type <typeparamref name="T" /> in <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
Returns The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> for chaining.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
public static
IServiceCollection
Replace​(IServiceCollection collection,
ServiceDescriptor descriptor)
Removes the first service in <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> with the same service type
as <paramref name="descriptor" /> and adds <paramref name="descriptor" /> to the collection.
Returns The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> for chaining.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
descriptor
The <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> to replace with.
public static
void
TryAdd​(IServiceCollection collection,
ServiceDescriptor descriptor)
Adds the specified <paramref name="descriptor" /> to the <paramref name="collection" /> if the
service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
descriptor
The <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> to add.
public static
void
TryAdd​(IServiceCollection collection,
System.​Collections.​Generic.​IEnumerable<​ServiceDescriptor> descriptors)
Adds the specified <paramref name="descriptors" /> to the <paramref name="collection" /> if the
service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
descriptors
The <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> s to add.
public static
void
TryAddEnumerable​(IServiceCollection services,
ServiceDescriptor descriptor)
Adds a <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> if an existing descriptor with the same
<see cref="P:Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ServiceType" /> and an implementation that does not already exist
in <paramref name="services" /> .
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
descriptor
The <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> .
Remarks
Use <see cref="M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddEnumerable(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.DependencyInjection.ServiceDescriptor)" /> when registering a service implementation of a
service type that
supports multiple registrations of the same service type. Using
<see cref="M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.Add(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.DependencyInjection.ServiceDescriptor)" /> is not idempotent and can add
duplicate
<see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> instances if called twice. Using
<see cref="M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddEnumerable(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.DependencyInjection.ServiceDescriptor)" /> will prevent registration
of multiple implementation types.
public static
void
TryAddEnumerable​(IServiceCollection services,
System.​Collections.​Generic.​IEnumerable<​ServiceDescriptor> descriptors)
Adds the specified <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> s if an existing descriptor with the same
<see cref="P:Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ServiceType" /> and an implementation that does not already exist
in <paramref name="services" /> .
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
descriptors
The <see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> s.
Remarks
Use <see cref="M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddEnumerable(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.DependencyInjection.ServiceDescriptor)" /> when registering a service
implementation of a service type that
supports multiple registrations of the same service type. Using
<see cref="M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.Add(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.DependencyInjection.ServiceDescriptor)" /> is not idempotent and can add
duplicate
<see cref="T:Microsoft.Extensions.DependencyInjection.ServiceDescriptor" /> instances if called twice. Using
<see cref="M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddEnumerable(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.DependencyInjection.ServiceDescriptor)" /> will prevent registration
of multiple implementation types.
public static
void
TryAddScoped​(IServiceCollection collection,
System.​Type service)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
public static
void
TryAddScoped​(IServiceCollection collection,
System.​Type service,
System.​Func<​System.​IServiceProvider, object> implementationFactory)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
implementationFactory
The factory that creates the service.
public static
void
TryAddScoped​(IServiceCollection collection,
System.​Type service,
System.​Type implementationType)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
with the <paramref name="implementationType" /> implementation
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
implementationType
The implementation type of the service.
public static
void
TryAddScoped​(IServiceCollection collection)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
public static
void
TryAddScoped​(IServiceCollection services,
System.​Func<​System.​IServiceProvider, TService> implementationFactory)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="services" /> if the service type hasn't already been registered.
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
implementationFactory
The factory that creates the service.
public static
void
TryAddScoped​(IServiceCollection collection)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
implementation type specified in <typeparamref name="TImplementation" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
public static
void
TryAddSingleton​(IServiceCollection collection,
System.​Type service)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
public static
void
TryAddSingleton​(IServiceCollection collection,
System.​Type service,
System.​Func<​System.​IServiceProvider, object> implementationFactory)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
implementationFactory
The factory that creates the service.
public static
void
TryAddSingleton​(IServiceCollection collection,
System.​Type service,
System.​Type implementationType)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
with the <paramref name="implementationType" /> implementation
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
implementationType
The implementation type of the service.
public static
void
TryAddSingleton​(IServiceCollection collection)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
public static
void
TryAddSingleton​(IServiceCollection services,
System.​Func<​System.​IServiceProvider, TService> implementationFactory)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="services" /> if the service type hasn't already been registered.
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
implementationFactory
The factory that creates the service.
public static
void
TryAddSingleton​(IServiceCollection collection,
TService instance)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
with an instance specified in <paramref name="instance" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
instance
The instance of the service to add.
public static
void
TryAddSingleton​(IServiceCollection collection)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
implementation type specified in <typeparamref name="TImplementation" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
public static
void
TryAddTransient​(IServiceCollection collection,
System.​Type service)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
public static
void
TryAddTransient​(IServiceCollection collection,
System.​Type service,
System.​Func<​System.​IServiceProvider, object> implementationFactory)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
implementationFactory
The factory that creates the service.
public static
void
TryAddTransient​(IServiceCollection collection,
System.​Type service,
System.​Type implementationType)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
with the <paramref name="implementationType" /> implementation
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
implementationType
The implementation type of the service.
public static
void
TryAddTransient​(IServiceCollection collection)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
public static
void
TryAddTransient​(IServiceCollection services,
System.​Func<​System.​IServiceProvider, TService> implementationFactory)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="services" /> if the service type hasn't already been registered.
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
implementationFactory
The factory that creates the service.
public static
void
TryAddTransient​(IServiceCollection collection)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
implementation type specified in <typeparamref name="TImplementation" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
public static
IServiceCollection
RemoveAllKeyed​(IServiceCollection collection,
System.​Type serviceType,
object serviceKey)
Removes all services of type <paramref name="serviceType" /> in <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
Returns The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> for chaining.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceType
The service type to remove.
serviceKey
The service key.
public static
IServiceCollection
RemoveAllKeyed​(IServiceCollection collection,
object serviceKey)
Removes all services of type <typeparamref name="T" /> in <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
Returns The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> for chaining.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
public static
void
TryAddKeyedScoped​(IServiceCollection collection,
System.​Type service,
object serviceKey)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
public static
void
TryAddKeyedScoped​(IServiceCollection collection,
System.​Type service,
object serviceKey,
System.​Func<​System.​IServiceProvider, object, object> implementationFactory)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
implementationFactory
The factory that creates the service.
public static
void
TryAddKeyedScoped​(IServiceCollection collection,
System.​Type service,
object serviceKey,
System.​Type implementationType)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
with the <paramref name="implementationType" /> implementation
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
implementationType
The implementation type of the service.
public static
void
TryAddKeyedScoped​(IServiceCollection collection,
object serviceKey)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
public static
void
TryAddKeyedScoped​(IServiceCollection services,
object serviceKey,
System.​Func<​System.​IServiceProvider, object, TService> implementationFactory)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="services" /> if the service type hasn't already been registered.
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
implementationFactory
The factory that creates the service.
public static
void
TryAddKeyedScoped​(IServiceCollection collection,
object serviceKey)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped" /> service
implementation type specified in <typeparamref name="TImplementation" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
public static
void
TryAddKeyedSingleton​(IServiceCollection collection,
System.​Type service,
object serviceKey)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
public static
void
TryAddKeyedSingleton​(IServiceCollection collection,
System.​Type service,
object serviceKey,
System.​Func<​System.​IServiceProvider, object, object> implementationFactory)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
implementationFactory
The factory that creates the service.
public static
void
TryAddKeyedSingleton​(IServiceCollection collection,
System.​Type service,
object serviceKey,
System.​Type implementationType)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
with the <paramref name="implementationType" /> implementation
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
implementationType
The implementation type of the service.
public static
void
TryAddKeyedSingleton​(IServiceCollection collection,
object serviceKey)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
public static
void
TryAddKeyedSingleton​(IServiceCollection services,
object serviceKey,
System.​Func<​System.​IServiceProvider, object, TService> implementationFactory)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="services" /> if the service type hasn't already been registered.
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
implementationFactory
The factory that creates the service.
public static
void
TryAddKeyedSingleton​(IServiceCollection collection,
object serviceKey,
TService instance)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
with an instance specified in <paramref name="instance" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
instance
The instance of the service to add.
public static
void
TryAddKeyedSingleton​(IServiceCollection collection,
object serviceKey)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton" /> service
implementation type specified in <typeparamref name="TImplementation" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
public static
void
TryAddKeyedTransient​(IServiceCollection collection,
System.​Type service,
object serviceKey)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
public static
void
TryAddKeyedTransient​(IServiceCollection collection,
System.​Type service,
object serviceKey,
System.​Func<​System.​IServiceProvider, object, object> implementationFactory)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
implementationFactory
The factory that creates the service.
public static
void
TryAddKeyedTransient​(IServiceCollection collection,
System.​Type service,
object serviceKey,
System.​Type implementationType)
Adds the specified <paramref name="service" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
with the <paramref name="implementationType" /> implementation
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
service
The type of the service to register.
serviceKey
The service key.
implementationType
The implementation type of the service.
public static
void
TryAddKeyedTransient​(IServiceCollection collection,
object serviceKey)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
public static
void
TryAddKeyedTransient​(IServiceCollection services,
object serviceKey,
System.​Func<​System.​IServiceProvider, object, TService> implementationFactory)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
using the factory specified in <paramref name="implementationFactory" />
to the <paramref name="services" /> if the service type hasn't already been registered.
services
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
implementationFactory
The factory that creates the service.
public static
void
TryAddKeyedTransient​(IServiceCollection collection,
object serviceKey)
Adds the specified <typeparamref name="TService" /> as a <see cref="F:Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient" /> service
implementation type specified in <typeparamref name="TImplementation" />
to the <paramref name="collection" /> if the service type hasn't already been registered.
collection
The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> .
serviceKey
The service key.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object