Merge branch 'rel/2.0.0-preview1' into dev

This commit is contained in:
John Luo 2017-05-05 17:11:49 -07:00
commit 3485a04ea1
4 changed files with 42 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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)" />

View File

@ -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)

View File

@ -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()
{