Showing posts with label ConfigureServices. Show all posts
Showing posts with label ConfigureServices. Show all posts

Tuesday, April 3, 2018

Configure vs ConfigureServices in ASP.NET Core 2.0

Both words sound similar but there is a very thin line which differentiates these two. Let’s have a look at key differences between these two methods.

Main purpose
Does all the initial setup
Does service configurations
Default Location
Resides in Startup.cs
Resides in Startup.cs
Execution sequence
Hits prior to ConfigureServices
Hits after Configure
Order of steps mentioned in this method matters
Order of the statements written to add services doesn’t matter
HTTP request
HTTP request first hits in this method
Configure(IApplicationBuilder app, IHostingEnvironment env)
ConfigureServices(IServiceCollection services)
Setting up all the middleware are done in this method
All the required services are added in this method

Note: All the services which are added to IServiceCollection can be utilized across the application.