Merge branch 'rel/2.0.0-preview1' into dev
This commit is contained in:
commit
3485a04ea1
|
|
@ -0,0 +1,25 @@
|
|||
// 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 System;
|
||||
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNetCore.Hosting.Internal
|
||||
{
|
||||
public class ApplicationDiscriminator : IApplicationDiscriminator
|
||||
{
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public ApplicationDiscriminator(IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
if (hostingEnvironment == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||
}
|
||||
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
public string Discriminator => _hostingEnvironment.ContentRootPath;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Abstractions" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="$(AspNetCoreVersion)" />
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
||||
using Microsoft.AspNetCore.Hosting.Builder;
|
||||
using Microsoft.AspNetCore.Hosting.Internal;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -303,6 +304,7 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
var services = new ServiceCollection();
|
||||
services.AddSingleton(_hostingEnvironment);
|
||||
services.AddSingleton(_context);
|
||||
services.AddTransient<IApplicationDiscriminator, ApplicationDiscriminator>();
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(_hostingEnvironment.ContentRootPath)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Reflection;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting.Fakes;
|
||||
using Microsoft.AspNetCore.Hosting.Internal;
|
||||
|
|
@ -987,6 +988,19 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
Assert.IsType<FileNotFoundException>(ex.InnerExceptions[0].InnerException);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_SetsAppDescriminatorFromContentRoot()
|
||||
{
|
||||
var builder = CreateWebHostBuilder()
|
||||
.UseContentRoot(Environment.CurrentDirectory)
|
||||
.Configure(app => { })
|
||||
.UseServer(new TestServer());
|
||||
|
||||
var host = builder.Build();
|
||||
var applicationDiscriminator = host.Services.GetRequiredService<IApplicationDiscriminator>();
|
||||
Assert.Equal(Environment.CurrentDirectory, applicationDiscriminator.Discriminator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Build_DoesNotThrowIfUnloadableAssemblyNameInHostingStartupAssembliesAndCaptureStartupErrorsTrue()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue