Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the valid Configure signatures in Startup?

How are the valid parameters for Configure determined in the Startup class? Does anyone know where the documentation is for the acceptable parameters is?

For instance, both of the following are valid:

public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
like image 214
Joe Healy Avatar asked Nov 01 '17 16:11

Joe Healy


1 Answers

The startup methods ConfigureServices and Configure are called by convention and the passed parameters are determined at runtime, so there is no fixed signature to implement (unless explicitly implementing IStartup).

The ConfigureServices method allows only a single parameter: IServiceCollection. The method can have that argument or none at all. All other signatures will cause an InvalidOperationException when the application starts.

The Configure method is a lot more flexible. Apart from the actual IApplicationBuilder, which is required to set up the application’s middleware pipeline, you can add any parameter you want to it. The arguments will then be evaluated at runtime and resolved from dependency injection.

So you can pass any dependency that is registered in the service collection and as such can be resolved using dependency injection.

This is also documented in the application startup documentation:

Additional services, like IHostingEnvironment and ILoggerFactory may also be specified in the method signature, in which case these services will be injected if they are available.

like image 189
poke Avatar answered Oct 03 '22 13:10

poke