Implement DefaultBrowserServiceProvider using Microsoft.Extensions.DependencyInjection.ServiceCollection
This commit is contained in:
parent
e524994734
commit
b4a3c852c5
|
|
@ -4,6 +4,10 @@
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" />
|
<ProjectReference Include="..\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Blazor.Browser.Services
|
namespace Microsoft.AspNetCore.Blazor.Browser.Services
|
||||||
|
|
@ -11,10 +12,34 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Services
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultBrowserServiceProvider : IServiceProvider
|
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 />
|
/// <inheritdoc />
|
||||||
public object GetService(Type serviceType)
|
public object GetService(Type serviceType)
|
||||||
|
=> _underlyingProvider.GetService(serviceType);
|
||||||
|
|
||||||
|
private void AddDefaultServices(ServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// TODO: Add default services for HttpClient, IUrlHelper, etc.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue