100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

C# .NET Core Basics Cheat Sheet

C# .NET Core Basics Cheat Sheet

Introduces ASP.NET Core and .NET fundamentals: Program.cs setup, dependency injection lifetimes, configuration, and the dotnet CLI workflow.

2 PagesBeginnerApr 2, 2026

Minimal Program.cs

The entry point and hosting setup for a modern .NET app.

csharp
var builder = WebApplication.CreateBuilder(args);builder.Services.AddControllers();builder.Services.AddScoped<IOrderService, OrderService>();  // DI registrationvar app = builder.Build();app.MapGet("/health", () => "OK");app.MapControllers();app.Run();

Dependency Injection Lifetimes

Singleton, scoped, and transient service registration.

csharp
// Program.csbuilder.Services.AddSingleton<ICacheService, MemoryCacheService>(); // One instance for app lifetimebuilder.Services.AddScoped<IUserRepository, UserRepository>();      // One instance per requestbuilder.Services.AddTransient<IEmailSender, EmailSender>();         // New instance every resolution// Injected via constructorpublic class OrderService{    private readonly IUserRepository _repo;    public OrderService(IUserRepository repo) => _repo = repo;}

Configuration & Environments

Reading settings and branching on environment.

csharp
// appsettings.json: { "ConnectionStrings": { "Default": "..." } }var connStr = builder.Configuration.GetConnectionString("Default");var apiKey = builder.Configuration["ExternalApi:Key"];if (builder.Environment.IsDevelopment()){    app.UseDeveloperExceptionPage();}

Core Concepts

Building blocks every .NET Core project relies on.

  • dotnet CLI- dotnet new webapi, dotnet build, dotnet run, dotnet test, dotnet publish
  • Project SDK- <Project Sdk="Microsoft.NET.Sdk.Web"> in the .csproj defines the project type
  • Middleware pipeline- app.Use...() calls run in order for every request (auth, routing, CORS, etc.)
  • appsettings.json- Layered config; appsettings.{Environment}.json overrides the base settings file
  • Dependency Injection- Built into the framework via IServiceCollection; no third-party container required
  • NuGet- dotnet add package <Name> adds a dependency to the .csproj
  • Hosted services- IHostedService/BackgroundService for long-running background tasks
Pro Tip

Prefer AddScoped for anything that touches a DbContext or per-request state — injecting a scoped service into a singleton creates a captive dependency bug that's hard to diagnose.

Was this cheat sheet helpful?

Explore Topics

#CNETCoreBasics#CNETCoreBasicsCheatSheet#Programming#Beginner#MinimalProgramCs#DependencyInjectionLifetimes#ConfigurationEnvironments#CoreConcepts#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet