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)
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
andILoggerFactory
may also be specified in the method signature, in which case these services will be injected if they are available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With