:::: MENU ::::

Quick Tips to manage ConfigureServices Method in ASP.Net Core

When your application starts to grow then we need to configure lots of services in ConfigureServices method of startup.cs then this method starts to get messy. Here is Quick tips to keep your ConfigureServices method clean and tidy no matter how big your application will be.

[Tips] Use the power of extension methods. First separate similar type of services and move it inside extension method in separate file and call those extensions method  in ConfigureServices.

Example:

This is what it looks when all service is dumped in ConfigureServices method.

For demo purpose i put very little services but in real application there will be a lot more services.

Now, I will separate similar services in separate extension method. For this example i am separating swagger services to separate file inside AddSwaggerServices Extension.

[Bonus] If you want to know how to add swagger in ASP.Net Core Web API project then you can read here.

Now access that extension method in ConfigureServices method.

Now this looks cleaner than previous method. Still you can refactor those identity related services.

That’s it. Happy Coding  🙂