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

Commit

Permalink
Add support for IServiceProviderFactory<TContainerBuilder>
Browse files Browse the repository at this point in the history
- 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
davidfowl committed Aug 13, 2016
1 parent 12b5a29 commit cc814c6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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);
}
}
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();
}
}
}

0 comments on commit cc814c6

Please sign in to comment.