Ability to derive Startup from a base class and have "Configure" and "ConfigureServices" be invoked from the base class when present.

This commit is contained in:
dtkujawski 2015-02-12 17:40:14 -06:00
parent 6208698a5c
commit fe3675a9e0
4 changed files with 47 additions and 17 deletions

View File

@ -29,8 +29,8 @@ namespace Microsoft.AspNet.Hosting.Startup
{
var methodNameWithEnv = string.Format(CultureInfo.InvariantCulture, methodName, environmentName);
var methodNameWithNoEnv = string.Format(CultureInfo.InvariantCulture, methodName, "");
var methodInfo = startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithEnv)
?? startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithNoEnv);
var methodInfo = startupType.GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
?? startupType.GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
if (methodInfo == null)
{
if (required)

View File

@ -9,7 +9,7 @@ using System;
namespace Microsoft.AspNet.Hosting.Fakes
{
public class Startup
public class Startup : StartupBase
{
public Startup()
{

View File

@ -0,0 +1,29 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.OptionsModel;
using System;
namespace Microsoft.AspNet.Hosting.Fakes
{
public class StartupBase
{
public StartupBase()
{
}
public void ConfigureBaseClassServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<FakeOptions>(o =>
{
o.Configured = true;
o.Environment = "BaseClass";
});
}
}
}

View File

@ -42,6 +42,7 @@ namespace Microsoft.AspNet.Hosting.Tests
[InlineData("StaticProvider")]
[InlineData("Provider")]
[InlineData("ProviderArgs")]
[InlineData("BaseClass")]
public void StartupClassAddsConfigureServicesToApplicationServices(string environment)
{
var services = HostingServices.Create().BuildServiceProvider();