Add missing doc comments (#581)
Add missing doc comments https://github.com/aspnet/DependencyInjection/issues/568 * Remove empty NoWarn
This commit is contained in:
Родитель
4ea859efad
Коммит
d5e5aa7032
|
@ -7,7 +7,6 @@ Microsoft.Extensions.DependencyInjection.IServiceCollection</Description>
|
|||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Microsoft.Extensions.DependencyInjection.Abstractions</AssemblyName>
|
||||
<RootNamespace>Microsoft.Extensions.DependencyInjection.Abstractions</RootNamespace>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<DefineConstants>$(DefineConstants);ActivatorUtilities_In_DependencyInjection</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -8,13 +8,16 @@ using Microsoft.Extensions.DependencyInjection.Abstractions;
|
|||
|
||||
namespace Microsoft.Extensions.DependencyInjection.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for adding and removing services to an <see cref="IServiceCollection" />.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionDescriptorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="descriptor"/> to the <paramref name="collection"/>.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="descriptor">The <see cref="ServiceDescriptor"/>.</param>
|
||||
/// <param name="descriptor">The <see cref="ServiceDescriptor"/> to add.</param>
|
||||
/// <returns>A reference to the current instance of <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection Add(
|
||||
this IServiceCollection collection,
|
||||
|
@ -38,7 +41,7 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
/// Adds a sequence of <see cref="ServiceDescriptor"/> to the <paramref name="collection"/>.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="descriptors">The <see cref="IEnumerable{T}"/> of <see cref="ServiceDescriptor"/>s to add.</param>
|
||||
/// <param name="descriptors">The <see cref="ServiceDescriptor"/>s to add.</param>
|
||||
/// <returns>A reference to the current instance of <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection Add(
|
||||
this IServiceCollection collection,
|
||||
|
@ -64,10 +67,10 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="descriptor"/> to the <paramref name="collection"/> if the
|
||||
/// service type hasn't been already registered.
|
||||
/// service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="descriptor">The <see cref="ServiceDescriptor"/>.</param>
|
||||
/// <param name="descriptor">The <see cref="ServiceDescriptor"/> to add.</param>
|
||||
public static void TryAdd(
|
||||
this IServiceCollection collection,
|
||||
ServiceDescriptor descriptor)
|
||||
|
@ -90,10 +93,10 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="descriptors"/> to the <paramref name="collection"/> if the
|
||||
/// service type hasn't been already registered.
|
||||
/// service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="descriptors">The <see cref="ServiceDescriptor"/>s.</param>
|
||||
/// <param name="descriptors">The <see cref="ServiceDescriptor"/>s to add.</param>
|
||||
public static void TryAdd(
|
||||
this IServiceCollection collection,
|
||||
IEnumerable<ServiceDescriptor> descriptors)
|
||||
|
@ -114,6 +117,12 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="ServiceLifetime.Transient"/> service
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
public static void TryAddTransient(
|
||||
this IServiceCollection collection,
|
||||
Type service)
|
||||
|
@ -132,6 +141,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="ServiceLifetime.Transient"/> service
|
||||
/// with the <paramref name="implementationType"/> implementation
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
/// <param name="implementationType">The implementation type of the service.</param>
|
||||
public static void TryAddTransient(
|
||||
this IServiceCollection collection,
|
||||
Type service,
|
||||
|
@ -156,6 +173,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="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.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
public static void TryAddTransient(
|
||||
this IServiceCollection collection,
|
||||
Type service,
|
||||
|
@ -180,6 +205,12 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="ServiceLifetime.Transient"/> service
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
public static void TryAddTransient<TService>(this IServiceCollection collection)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -191,6 +222,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAddTransient(collection, typeof(TService), typeof(TService));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="ServiceLifetime.Transient"/> service
|
||||
/// implementation type specified in <typeparamref name="TImplementation"/>
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
public static void TryAddTransient<TService, TImplementation>(this IServiceCollection collection)
|
||||
where TService : class
|
||||
where TImplementation : class, TService
|
||||
|
@ -203,6 +242,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAddTransient(collection, typeof(TService), typeof(TImplementation));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="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.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
public static void TryAddTransient<TService>(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, TService> implementationFactory)
|
||||
|
@ -211,6 +258,12 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
services.TryAdd(ServiceDescriptor.Transient(implementationFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="ServiceLifetime.Scoped"/> service
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
public static void TryAddScoped(
|
||||
this IServiceCollection collection,
|
||||
Type service)
|
||||
|
@ -229,6 +282,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="ServiceLifetime.Scoped"/> service
|
||||
/// with the <paramref name="implementationType"/> implementation
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
/// <param name="implementationType">The implementation type of the service.</param>
|
||||
public static void TryAddScoped(
|
||||
this IServiceCollection collection,
|
||||
Type service,
|
||||
|
@ -253,6 +314,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="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.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
public static void TryAddScoped(
|
||||
this IServiceCollection collection,
|
||||
Type service,
|
||||
|
@ -277,6 +346,12 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="ServiceLifetime.Scoped"/> service
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
public static void TryAddScoped<TService>(this IServiceCollection collection)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -288,6 +363,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAddScoped(collection, typeof(TService), typeof(TService));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="ServiceLifetime.Scoped"/> service
|
||||
/// implementation type specified in <typeparamref name="TImplementation"/>
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
public static void TryAddScoped<TService, TImplementation>(this IServiceCollection collection)
|
||||
where TService : class
|
||||
where TImplementation : class, TService
|
||||
|
@ -300,6 +383,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAddScoped(collection, typeof(TService), typeof(TImplementation));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="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.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
public static void TryAddScoped<TService>(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, TService> implementationFactory)
|
||||
|
@ -308,6 +399,12 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
services.TryAdd(ServiceDescriptor.Scoped(implementationFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="ServiceLifetime.Singleton"/> service
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
public static void TryAddSingleton(
|
||||
this IServiceCollection collection,
|
||||
Type service)
|
||||
|
@ -326,6 +423,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="ServiceLifetime.Singleton"/> service
|
||||
/// with the <paramref name="implementationType"/> implementation
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
/// <param name="implementationType">The implementation type of the service.</param>
|
||||
public static void TryAddSingleton(
|
||||
this IServiceCollection collection,
|
||||
Type service,
|
||||
|
@ -350,6 +455,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <paramref name="service"/> as a <see cref="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.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="service">The type of the service to register.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
public static void TryAddSingleton(
|
||||
this IServiceCollection collection,
|
||||
Type service,
|
||||
|
@ -374,6 +487,12 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="ServiceLifetime.Singleton"/> service
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
public static void TryAddSingleton<TService>(this IServiceCollection collection)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -385,6 +504,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAddSingleton(collection, typeof(TService), typeof(TService));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="ServiceLifetime.Singleton"/> service
|
||||
/// implementation type specified in <typeparamref name="TImplementation"/>
|
||||
/// to the <paramref name="collection"/> if the service type hasn't already been registered.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
public static void TryAddSingleton<TService, TImplementation>(this IServiceCollection collection)
|
||||
where TService : class
|
||||
where TImplementation : class, TService
|
||||
|
@ -397,6 +524,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAddSingleton(collection, typeof(TService), typeof(TImplementation));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="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.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <param name="collection">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="instance">The instance of the service to add.</param>
|
||||
public static void TryAddSingleton<TService>(this IServiceCollection collection, TService instance)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -414,6 +549,14 @@ namespace Microsoft.Extensions.DependencyInjection.Extensions
|
|||
TryAdd(collection, descriptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified <typeparamref name="TService"/> as a <see cref="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.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
public static void TryAddSingleton<TService>(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, TService> implementationFactory)
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// A factory for creating instances of <see cref="IServiceScope"/>, which is used to create
|
||||
/// services within a scope.
|
||||
/// </summary>
|
||||
public interface IServiceScopeFactory
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -6,6 +6,9 @@ using System.Diagnostics;
|
|||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes a service with its service type, implementation, and lifetime.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Lifetime = {Lifetime}, ServiceType = {ServiceType}, ImplementationType = {ImplementationType}")]
|
||||
public class ServiceDescriptor
|
||||
{
|
||||
|
@ -127,6 +130,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <typeparamref name="TImplementation"/>,
|
||||
/// and the <see cref="ServiceLifetime.Transient"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Transient<TService, TImplementation>()
|
||||
where TService : class
|
||||
where TImplementation : class, TService
|
||||
|
@ -134,6 +145,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe<TService, TImplementation>(ServiceLifetime.Transient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="service"/> and <paramref name="implementationType"/>
|
||||
/// and the <see cref="ServiceLifetime.Transient"/> lifetime.
|
||||
/// </summary>
|
||||
/// <param name="service">The type of the service.</param>
|
||||
/// <param name="implementationType">The type of the implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Transient(Type service, Type implementationType)
|
||||
{
|
||||
if (service == null)
|
||||
|
@ -149,6 +168,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(service, implementationType, ServiceLifetime.Transient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <typeparamref name="TImplementation"/>,
|
||||
/// <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Transient"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Transient<TService, TImplementation>(
|
||||
Func<IServiceProvider, TImplementation> implementationFactory)
|
||||
where TService : class
|
||||
|
@ -162,6 +191,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(typeof(TService), implementationFactory, ServiceLifetime.Transient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Transient"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Transient<TService>(Func<IServiceProvider, TService> implementationFactory)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -173,8 +210,15 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(typeof(TService), implementationFactory, ServiceLifetime.Transient);
|
||||
}
|
||||
|
||||
public static ServiceDescriptor Transient(Type service,
|
||||
Func<IServiceProvider, object> implementationFactory)
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="service"/>, <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Transient"/> lifetime.
|
||||
/// </summary>
|
||||
/// <param name="service">The type of the service.</param>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Transient(Type service, Func<IServiceProvider, object> implementationFactory)
|
||||
{
|
||||
if (service == null)
|
||||
{
|
||||
|
@ -189,6 +233,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(service, implementationFactory, ServiceLifetime.Transient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <typeparamref name="TImplementation"/>,
|
||||
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Scoped<TService, TImplementation>()
|
||||
where TService : class
|
||||
where TImplementation : class, TService
|
||||
|
@ -196,11 +248,29 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe<TService, TImplementation>(ServiceLifetime.Scoped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="service"/> and <paramref name="implementationType"/>
|
||||
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
|
||||
/// </summary>
|
||||
/// <param name="service">The type of the service.</param>
|
||||
/// <param name="implementationType">The type of the implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Scoped(Type service, Type implementationType)
|
||||
{
|
||||
return Describe(service, implementationType, ServiceLifetime.Scoped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <typeparamref name="TImplementation"/>,
|
||||
/// <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Scoped<TService, TImplementation>(
|
||||
Func<IServiceProvider, TImplementation> implementationFactory)
|
||||
where TService : class
|
||||
|
@ -214,6 +284,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(typeof(TService), implementationFactory, ServiceLifetime.Scoped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Scoped<TService>(Func<IServiceProvider, TService> implementationFactory)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -225,9 +303,15 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(typeof(TService), implementationFactory, ServiceLifetime.Scoped);
|
||||
}
|
||||
|
||||
public static ServiceDescriptor Scoped
|
||||
(Type service,
|
||||
Func<IServiceProvider, object> implementationFactory)
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="service"/>, <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
|
||||
/// </summary>
|
||||
/// <param name="service">The type of the service.</param>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Scoped(Type service, Func<IServiceProvider, object> implementationFactory)
|
||||
{
|
||||
if (service == null)
|
||||
{
|
||||
|
@ -242,6 +326,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(service, implementationFactory, ServiceLifetime.Scoped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <typeparamref name="TImplementation"/>,
|
||||
/// and the <see cref="ServiceLifetime.Singleton"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Singleton<TService, TImplementation>()
|
||||
where TService : class
|
||||
where TImplementation : class, TService
|
||||
|
@ -249,6 +341,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe<TService, TImplementation>(ServiceLifetime.Singleton);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="service"/> and <paramref name="implementationType"/>
|
||||
/// and the <see cref="ServiceLifetime.Singleton"/> lifetime.
|
||||
/// </summary>
|
||||
/// <param name="service">The type of the service.</param>
|
||||
/// <param name="implementationType">The type of the implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Singleton(Type service, Type implementationType)
|
||||
{
|
||||
if (service == null)
|
||||
|
@ -264,6 +364,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(service, implementationType, ServiceLifetime.Singleton);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <typeparamref name="TImplementation"/>,
|
||||
/// <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Singleton"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Singleton<TService, TImplementation>(
|
||||
Func<IServiceProvider, TImplementation> implementationFactory)
|
||||
where TService : class
|
||||
|
@ -277,6 +387,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(typeof(TService), implementationFactory, ServiceLifetime.Singleton);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Singleton"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Singleton<TService>(Func<IServiceProvider, TService> implementationFactory)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -288,6 +406,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(typeof(TService), implementationFactory, ServiceLifetime.Singleton);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="serviceType"/>, <paramref name="implementationFactory"/>,
|
||||
/// and the <see cref="ServiceLifetime.Singleton"/> lifetime.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">The type of the service.</param>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Singleton(
|
||||
Type serviceType,
|
||||
Func<IServiceProvider, object> implementationFactory)
|
||||
|
@ -305,6 +431,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Describe(serviceType, implementationFactory, ServiceLifetime.Singleton);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <typeparamref name="TService"/>, <paramref name="implementationInstance"/>,
|
||||
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
|
||||
/// </summary>
|
||||
/// <typeparam name="TService">The type of the service.</typeparam>
|
||||
/// <param name="implementationInstance">The instance of the implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Singleton<TService>(TService implementationInstance)
|
||||
where TService : class
|
||||
{
|
||||
|
@ -316,6 +450,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return Singleton(typeof(TService), implementationInstance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="serviceType"/>, <paramref name="implementationInstance"/>,
|
||||
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">The type of the service.</param>
|
||||
/// <param name="implementationInstance">The instance of the implementation.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Singleton(
|
||||
Type serviceType,
|
||||
object implementationInstance)
|
||||
|
@ -343,11 +485,29 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
lifetime: lifetime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="serviceType"/>, <paramref name="implementationType"/>,
|
||||
/// and <paramref name="lifetime"/>.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">The type of the service.</param>
|
||||
/// <param name="implementationType">The type of the implementation.</param>
|
||||
/// <param name="lifetime">The lifetime of the service.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Describe(Type serviceType, Type implementationType, ServiceLifetime lifetime)
|
||||
{
|
||||
return new ServiceDescriptor(serviceType, implementationType, lifetime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
|
||||
/// <paramref name="serviceType"/>, <paramref name="implementationFactory"/>,
|
||||
/// and <paramref name="lifetime"/>.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">The type of the service.</param>
|
||||
/// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
|
||||
/// <param name="lifetime">The lifetime of the service.</param>
|
||||
/// <returns>A new instance of <see cref="ServiceDescriptor"/>.</returns>
|
||||
public static ServiceDescriptor Describe(Type serviceType, Func<IServiceProvider, object> implementationFactory, ServiceLifetime lifetime)
|
||||
{
|
||||
return new ServiceDescriptor(serviceType, implementationFactory, lifetime);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Microsoft.Extensions.DependencyInjection</AssemblyName>
|
||||
<RootNamespace>Microsoft.Extensions.DependencyInjection</RootNamespace>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -2,15 +2,28 @@
|
|||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Default implementation of <see cref="IServiceProviderFactory{TContainerBuilder}"/>.
|
||||
/// </summary>
|
||||
public class DefaultServiceProviderFactory : IServiceProviderFactory<IServiceCollection>
|
||||
{
|
||||
private readonly ServiceProviderOptions _options;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DefaultServiceProviderFactory"/> class
|
||||
/// with default options.
|
||||
/// </summary>
|
||||
/// <seealso cref="ServiceProviderOptions.Default"/>
|
||||
public DefaultServiceProviderFactory() : this(ServiceProviderOptions.Default)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DefaultServiceProviderFactory"/> class
|
||||
/// with the specified <paramref name="options"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The options to use for this instance.</param>
|
||||
public DefaultServiceProviderFactory(ServiceProviderOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
|
@ -21,11 +34,13 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
_options = options;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IServiceCollection CreateBuilder(IServiceCollection services)
|
||||
{
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IServiceProvider CreateServiceProvider(IServiceCollection containerBuilder)
|
||||
{
|
||||
return containerBuilder.BuildServiceProvider(_options);
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
/// <inheritdoc />
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ServiceDescriptor this[int index]
|
||||
{
|
||||
get
|
||||
|
@ -71,16 +72,19 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int IndexOf(ServiceDescriptor item)
|
||||
{
|
||||
return _descriptors.IndexOf(item);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Insert(int index, ServiceDescriptor item)
|
||||
{
|
||||
_descriptors.Insert(index, item);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
_descriptors.RemoveAt(index);
|
||||
|
|
|
@ -5,6 +5,9 @@ using System;
|
|||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for building a <see cref="ServiceProvider"/> from an <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionContainerBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
|
|
Загрузка…
Ссылка в новой задаче