This repository was archived by the owner on Dec 19, 2018. It is now read-only.
File tree 4 files changed +42
-0
lines changed
src/Microsoft.AspNetCore.Hosting
test/Microsoft.AspNetCore.Hosting.Tests
4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+ using System ;
5
+ using Microsoft . AspNetCore . DataProtection . Infrastructure ;
6
+
7
+ namespace Microsoft . AspNetCore . Hosting . Internal
8
+ {
9
+ public class ApplicationDiscriminator : IApplicationDiscriminator
10
+ {
11
+ private readonly IHostingEnvironment _hostingEnvironment ;
12
+
13
+ public ApplicationDiscriminator ( IHostingEnvironment hostingEnv )
14
+ {
15
+ if ( hostingEnv == null )
16
+ {
17
+ throw new ArgumentNullException ( nameof ( hostingEnv ) ) ;
18
+ }
19
+
20
+ _hostingEnvironment = hostingEnv ;
21
+ }
22
+
23
+ public string Discriminator => _hostingEnvironment . ContentRootPath ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change 17
17
</ItemGroup >
18
18
19
19
<ItemGroup >
20
+ <PackageReference Include =" Microsoft.AspNetCore.DataProtection.Abstractions" Version =" $(AspNetCoreVersion)" />
20
21
<PackageReference Include =" Microsoft.AspNetCore.Http" Version =" $(AspNetCoreVersion)" />
21
22
<PackageReference Include =" Microsoft.AspNetCore.Http.Extensions" Version =" $(AspNetCoreVersion)" />
22
23
<PackageReference Include =" Microsoft.Extensions.Configuration" Version =" $(AspNetCoreVersion)" />
Original file line number Diff line number Diff line change 7
7
using System . IO ;
8
8
using System . Reflection ;
9
9
using System . Runtime . ExceptionServices ;
10
+ using Microsoft . AspNetCore . DataProtection . Infrastructure ;
10
11
using Microsoft . AspNetCore . Hosting . Builder ;
11
12
using Microsoft . AspNetCore . Hosting . Internal ;
12
13
using Microsoft . AspNetCore . Http ;
@@ -303,6 +304,7 @@ private IServiceCollection BuildCommonServices(out AggregateException hostingSta
303
304
var services = new ServiceCollection ( ) ;
304
305
services . AddSingleton ( _hostingEnvironment ) ;
305
306
services . AddSingleton ( _context ) ;
307
+ services . AddTransient < IApplicationDiscriminator , ApplicationDiscriminator > ( ) ;
306
308
307
309
var builder = new ConfigurationBuilder ( )
308
310
. SetBasePath ( _hostingEnvironment . ContentRootPath )
Original file line number Diff line number Diff line change 9
9
using System . Threading ;
10
10
using System . Threading . Tasks ;
11
11
using Microsoft . AspNetCore . Builder ;
12
+ using Microsoft . AspNetCore . DataProtection . Infrastructure ;
12
13
using Microsoft . AspNetCore . Hosting ;
13
14
using Microsoft . AspNetCore . Hosting . Fakes ;
14
15
using Microsoft . AspNetCore . Hosting . Internal ;
@@ -987,6 +988,19 @@ public void Build_ThrowsIfUnloadableAssemblyNameInHostingStartupAssemblies()
987
988
Assert . IsType < FileNotFoundException > ( ex . InnerExceptions [ 0 ] . InnerException ) ;
988
989
}
989
990
991
+ [ Fact ]
992
+ public void Build_SetsAppDescriminatorFromContentRoot ( )
993
+ {
994
+ var builder = CreateWebHostBuilder ( )
995
+ . UseContentRoot ( Environment . CurrentDirectory )
996
+ . Configure ( app => { } )
997
+ . UseServer ( new TestServer ( ) ) ;
998
+
999
+ var host = builder . Build ( ) ;
1000
+ var applicationDiscriminator = host . Services . GetRequiredService < IApplicationDiscriminator > ( ) ;
1001
+ Assert . Equal ( Environment . CurrentDirectory , applicationDiscriminator . Discriminator ) ;
1002
+ }
1003
+
990
1004
[ Fact ]
991
1005
public async Task Build_DoesNotThrowIfUnloadableAssemblyNameInHostingStartupAssembliesAndCaptureStartupErrorsTrue ( )
992
1006
{
You can’t perform that action at this time.
0 commit comments