Cheat Sheet: ASP.NET Core
aspnet core

Series of short snippets of FUC. This one is for Azure SDKs.
July 2, 2018

I often find myself searching the internet for the same four lines of C# all over again, because of my inability to remember anything and the complexity of my filesystem structure... That's why I decided to start putting together quick snippets of Frequently Used Code (FUC).

This one is about ASP.NET Core.

It's a living document, I keep updating it.


Startup.cs -> ConfigureServices():


Startup.cs -> Configure():

app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());

Location of NuGet packages

NuGet packages are installed to:


Service lifetimes in dependency injection

Transient: Created each time they're requested from service container. Best for lighweight, stateless services.

Scoped: Created once per client request (connection).

Singleton: Created the first time they're requested (or when ConfigureServices is run and service is registered with an instance). Every subsequent request uses the same instance.


Disposal of services

Only services created by the service container are disposed of automatically.

Found something inaccurate or plain wrong? Was this content helpful to you? Let me know!