Application startup
Startup class
The Startup
class (which is named Startup
just by convention) is where:
The request handling pipeline is defined (
Configure
method).[OPTIONAL] Configured services required by the app (
ConfigureServices
method).
Dependency injection works even for Startup class!
A common use of dependency injection into the Startup
class is to inject:
IHostingEnvironment
to configure services by environment.IConfiguration
to read configuration.ILoggerFactory
to create a logger inStartup.ConfigureServices
Building app's host
The Startup
class is specified to the app when the app's host is built. The Startup
class is usually specified by calling the WebHostBuilderExtensions.UseStartup<TStartup>
method on the host builder:
You can build webhost even without Startup class!
To configure services and the request processing pipeline without using a Startup
class, call ConfigureServices
and Configure
convenience methods on the host builder.
Last updated