This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for IServiceProviderFactory<TContainerBuilder>
- A new abstraction that allows the DI container author to describe how to translate an IServiceCollection to a specific container and then to an IServiceProvider. - Hosting will use this abstraction to swap out the default container
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/Microsoft.Extensions.DependencyInjection.Abstractions/IServiceProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Provides an extension point for creating a container specific builder and an <see cref="IServiceProvider"/>. | ||
/// </summary> | ||
public interface IServiceProviderFactory<TContainerBuilder> | ||
{ | ||
/// <summary> | ||
/// Creates a container builder from an <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
/// <param name="services">The collection of services</param> | ||
/// <returns>A container builder that can be used to create an <see cref="IServiceProvider"/>.</returns> | ||
TContainerBuilder CreateBuilder(IServiceCollection services); | ||
|
||
/// <summary> | ||
/// Creates an <see cref="IServiceProvider"/> from the container builder. | ||
/// </summary> | ||
/// <param name="containerBuilder">The container builder</param> | ||
/// <returns>An <see cref="IServiceProvider"/></returns> | ||
IServiceProvider CreateServiceProvider(TContainerBuilder containerBuilder); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Microsoft.Extensions.DependencyInjection/DefaultServiceProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public class DefaultServiceProviderFactory : IServiceProviderFactory<IServiceCollection> | ||
{ | ||
public IServiceCollection CreateBuilder(IServiceCollection services) | ||
{ | ||
return services; | ||
} | ||
|
||
public IServiceProvider CreateServiceProvider(IServiceCollection containerBuilder) | ||
{ | ||
return containerBuilder.BuildServiceProvider(); | ||
} | ||
} | ||
} |