From 68092dbb974984ec0c14bd47b555cda8ddcf42ea Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 19 Apr 2016 10:29:25 -0700 Subject: [PATCH] Porting #712 to release --- .../WebHostBuilder.cs | 2 +- .../WebHostBuilderTests.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index af33553886..57168deaa1 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -254,7 +254,7 @@ namespace Microsoft.AspNetCore.Hosting { if (_startup != null) { - return _startup.ConfigureDelegate.Target.GetType().GetTypeInfo().Assembly.GetName().Name; + return _startup.ConfigureDelegate.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name; } if (_startupType != null) { diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs index 40a2c1b545..afe4384b65 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Fakes; using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Hosting.Server; @@ -477,6 +478,33 @@ namespace Microsoft.AspNetCore.Hosting Assert.Equal(PlatformServices.Default.Application.ApplicationBasePath, appEnv.ApplicationBasePath); } + [Fact] + public void Configure_SupportsNonStaticMethodDelegate() + { + var host = new WebHostBuilder() + .UseServer(new TestServer()) + .Configure(app => { }) + .Build(); + + var hostingEnv = host.Services.GetService(); + Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); + } + + [Fact] + public void Configure_SupportsStaticMethodDelegate() + { + var host = new WebHostBuilder() + .UseServer(new TestServer()) + .Configure(StaticConfigureMethod) + .Build(); + + var hostingEnv = host.Services.GetService(); + Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); + } + + private static void StaticConfigureMethod(IApplicationBuilder app) + { } + private IWebHostBuilder CreateWebHostBuilder() { var vals = new Dictionary