Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Allowing Configure method to be inherited by Startup class #105

Closed
matthewhancock opened this issue Oct 15, 2014 · 4 comments
Closed

Allowing Configure method to be inherited by Startup class #105

matthewhancock opened this issue Oct 15, 2014 · 4 comments

Comments

@matthewhancock
Copy link

I'm going to have multiple web applications sharing base code and it would be great if the Startup class could inherit the Configure method from a parent class. Otherwise, I'm going to have to copy and paste the same boilerplate.

e.g. this wouldn't fail

    public class Startup : StartupTemplate
    {
        public override async Task ProcessRequestAsync(HttpContext Context)
        {
            await Context.Response.WriteAsync("Hello World");
        }
    }
    public abstract class StartupTemplate
    {
        public void Configure(IApplicationBuilder app)
        {
            app.Run(ProcessRequestAsync);
        }
        public abstract Task ProcessRequestAsync(HttpContext Context);
    }

This returns the basic Configure not found error:

    System.Exception: TODO: ConfigureDevelopment or Configure method not found
    at Microsoft.AspNet.Hosting.Startup.StartupLoader.LoadStartup(String applicationName, String environmentName, IList`1 diagnosticMessages)

It looks like the update would need to be here: https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs

    var methodInfo = startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithEnv)
    ?? startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithNoEnv);

Could GetDeclaredMethod be replaced with GetMethod(String, BindingFlags)?

@dtkujawski
Copy link
Contributor

I ran into this same issue and also believe that not requiring declared methods is a good idea so that we can derive the Startup.cs file from a base class.

Changing the line method above to the following would be nice:

var methodInfo = startupType.GetTypeInfo().GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance)
        ?? startupType.GetTypeInfo().GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance);

@glennc
Copy link
Member

glennc commented Feb 12, 2015

We are ok with taking this change if either of you guys want to submit a pull request, see the instructions if you haven't done it before.

@glennc glennc added this to the Backlog milestone Feb 12, 2015
@dtkujawski
Copy link
Contributor

My first time doing a pull request, so let me know if I did it wrong: #153

@Eilon
Copy link
Member

Eilon commented Mar 2, 2015

#153 fixed this.

@Eilon Eilon closed this as completed Mar 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants