Implement DefaultBrowserServiceProvider using Microsoft.Extensions.DependencyInjection.ServiceCollection

This commit is contained in:
Steve Sanderson 2018-02-22 18:47:07 +00:00
parent e524994734
commit b4a3c852c5
2 changed files with 30 additions and 1 deletions

View File

@ -4,6 +4,10 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" />
</ItemGroup>

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Microsoft.AspNetCore.Blazor.Browser.Services
@ -11,10 +12,34 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Services
/// </summary>
public class DefaultBrowserServiceProvider : IServiceProvider
{
private readonly IServiceProvider _underlyingProvider;
/// <summary>
/// Constructs an instance of <see cref="DefaultBrowserServiceProvider"/>.
/// </summary>
public DefaultBrowserServiceProvider(): this(null)
{
}
/// <summary>
/// Constructs an instance of <see cref="DefaultBrowserServiceProvider"/>.
/// </summary>
/// <param name="configure">A callback that can be used to configure the <see cref="IServiceCollection"/>.</param>
public DefaultBrowserServiceProvider(Action<IServiceCollection> configure)
{
var serviceCollection = new ServiceCollection();
AddDefaultServices(serviceCollection);
configure?.Invoke(serviceCollection);
_underlyingProvider = serviceCollection.BuildServiceProvider();
}
/// <inheritdoc />
public object GetService(Type serviceType)
=> _underlyingProvider.GetService(serviceType);
private void AddDefaultServices(ServiceCollection serviceCollection)
{
throw new NotImplementedException();
// TODO: Add default services for HttpClient, IUrlHelper, etc.
}
}
}