[Intermediate] · What .NET ships with, the packages everyone uses, and dependency injection as a first-class citizen.

The BCL

.NET’s Base Class Library is large and unusually coherent — one vendor, one design review, consistent naming.

NeedType
Files and pathsFile, Directory, Path, FileStream
HTTPHttpClient
JSONSystem.Text.Json
DatesDateTime, DateTimeOffset, TimeSpan, DateOnly/TimeOnly
RegexSystem.Text.RegularExpressions
CryptoSystem.Security.Cryptography, RandomNumberGenerator
ConcurrencyTask, Channel<T>, SemaphoreSlim, Interlocked, Concurrent*
Logging abstractionMicrosoft.Extensions.Logging
ConfigMicrosoft.Extensions.Configuration
DIMicrosoft.Extensions.DependencyInjection

Three traps worth naming, because each has caused real production incidents:

HttpClient must be reused, not created per request. A using var client = new HttpClient() in a loop exhausts sockets — disposed clients leave connections in TIME_WAIT → TCP. Use IHttpClientFactory, which also handles DNS rotation, which a long-lived static HttpClient does not.

DateTime is ambiguous; DateTimeOffset isn’t. DateTime carries a Kind (Utc/Local/Unspecified) that is easy to lose across serialisation. Store UTC, use DateTimeOffset for anything with a real instant, and DateOnly for birthdays and calendar dates → the same rule in Python.

Random is not secure. For tokens, passwords or anything an attacker benefits from predicting, use RandomNumberGenerator → cryptography.

Dependency injection, built in

This is a genuine structural difference from most ecosystems. DI isn’t a framework you add; it’s in the platform, and the whole ASP.NET Core stack is built on it.

var builder = WebApplication.CreateBuilder(args);
 
builder.Services.AddSingleton<IClock, SystemClock>();      // one, forever
builder.Services.AddScoped<IOrderService, OrderService>(); // one per request
builder.Services.AddTransient<IEmailSender, SmtpSender>(); // one per resolution
builder.Services.AddHttpClient<GitHubClient>();
 
var app = builder.Build();

The three lifetimes, and the bug they cause:

One instance perUse for
SingletonProcessStateless services, caches, config
ScopedRequestAnything holding per-request state — a DbContext
TransientResolutionCheap, stateless, short-lived

The classic bug: injecting a Scoped service into a Singleton. The scoped service is then captured for the lifetime of the singleton — so a DbContext meant to live for one request lives forever, accumulating tracked entities and becoming thread-unsafe. .NET detects this at startup in development (ValidateScopes), which is worth leaving on.

Why this matters beyond convenience: because DI is universal here, C# code is structurally testable — you substitute an interface rather than patching. It’s the practical answer to the Singleton problem → why Singleton is global state.

The packages you’ll actually meet

ASP.NET CoreWeb APIs, MVC, Blazor, SignalR — in the SDK, not a package
Entity Framework CoreThe default ORM → databases
DapperMicro-ORM; you write the SQL. Faster, more control
SerilogStructured logging → observability
xUnit / NUnitTesting → note 12
FluentValidationValidation rules as code
MediatRIn-process messaging; popular, and easy to overuse
PollyRetries, circuit breakers, timeouts
BenchmarkDotNetThe standard microbenchmark tool, and genuinely excellent
AutoMapperObject mapping. Widely used, widely regretted — it hides mistakes the compiler would catch

NuGet is the package manager; dotnet add package is the interface.

EF Core, and the trap

var orders = await db.Orders
    .Include(o => o.Customer)                     // eager load — avoids N+1
    .Where(o => o.Total > 100)
    .AsNoTracking()                               // read-only: faster
    .ToListAsync(ct);

The N+1 problem is identical to every other ORM’s → Django:

foreach (var o in db.Orders.ToList())     // 1 query
    Console.WriteLine(o.Customer.Name);   // + 1 per order

Include is the fix; lazy loading is the cause. And AsNoTracking on read-only queries is free performance — the change tracker is doing work you’re throwing away.

The IQueryable boundary matters most here — .ToList() in the wrong place moves the filter from SQL into C# and loads the whole table → note 04.

What .NET does badly

Windows-shaped assumptions persist in older libraries and in a lot of documentation, even though the platform is genuinely cross-platform now.

The ecosystem is narrower than the JVM’s or Python’s for data science, ML and scientific computing — ML.NET exists and is not where the field is.

Microsoft dependency. Open source, .NET Foundation governed, and still overwhelmingly one company’s roadmap. Some people consider that a risk; it’s a legitimate input to a trade study → trade studies.

Source: [reference] — from the .NET documentation, Aug 2026.

↑ Back to C#