Essential dotnet CLI Commands and Project Structure
Every .NET Core project starts from the CLI: dotnet new webapi -n MyApi scaffolds a new Web API project, dotnet run compiles and launches it, dotnet add package <Name> adds a NuGet dependency to the nearest .csproj, and dotnet ef migrations add <Name> (with the EF Core tools installed) generates a database migration. A typical project's structure separates Program.cs (the composition root and minimal API/middleware pipeline), appsettings.json (configuration), and folders like Controllers/, Models/, and Services/ that map cleanly onto the layers of a typical web application.
Cricket analogy: dotnet new webapi -n MyApi is like a franchise announcing a brand-new team with one command — instantly provisioning a stadium, kit, and starting eleven template ready to be customized.
Collections and LINQ Quick Facts
LINQ methods like .Where(), .Select(), and .OrderBy() on an IEnumerable<T> are deferred/lazy — the query doesn't execute until you enumerate it (via foreach, .ToList(), or .Count()), which means a query built from a stale data source can return different results if the source changes before enumeration. List<T> offers O(1) index access and O(1) amortized Add, while Dictionary<TKey,TValue> offers average O(1) lookup by key; picking the wrong collection (e.g., List<T>.Contains() for frequent membership checks, which is O(n)) is a common source of accidental quadratic-time bugs in code that looks innocent at a glance.
Cricket analogy: Deferred LINQ execution is like a bowling analysis that isn't calculated until the over actually finishes — the numbers reflect whatever deliveries were actually bowled at query time, not when you first set up the stat.
Configuration and appsettings Patterns
IConfiguration in ASP.NET Core reads from a layered set of sources — appsettings.json, then appsettings.{Environment}.json, then environment variables, then command-line arguments — with later sources overriding earlier ones, so a value set via an environment variable in production always wins over what's in the checked-in JSON file. The strongly-typed options pattern binds a JSON section to a POCO class via builder.Services.Configure<MySettings>(builder.Configuration.GetSection("MySettings")), then that class is injected as IOptions<MySettings> (or IOptionsSnapshot<T> for per-request reload) instead of scattering configuration["MySettings:Key"] magic strings throughout the codebase.
Cricket analogy: Layered configuration sources overriding each other is like a match's playing conditions being set by the ICC rulebook by default, then overridden by ground-specific regulations, then finally overridden by an on-field umpire's decision on the day.
// Strongly-typed options pattern
public class MySettings
{
public string ApiKey { get; set; } = string.Empty;
public int TimeoutSeconds { get; set; } = 30;
}
builder.Services.Configure<MySettings>(
builder.Configuration.GetSection("MySettings"));
app.MapGet("/config-check", (IOptions<MySettings> options) =>
Results.Ok(new { options.Value.TimeoutSeconds }));
// Deferred LINQ example
var names = new List<string> { "Asha", "Rahul", "Meera" };
IEnumerable<string> query = names.Where(n => n.StartsWith('A')); // not executed yet
names.Add("Aditya");
var result = query.ToList(); // now includes "Aditya" tooQuick CLI cheat sheet: dotnet new list (see available templates), dotnet restore, dotnet build, dotnet test, dotnet run, dotnet publish -c Release, dotnet add package <Name>, dotnet add reference <path>, dotnet ef migrations add <Name>, dotnet ef database update, dotnet tool install --global <ToolName>.
Calling .ToList() too early on a LINQ query forces immediate evaluation, which is usually fine, but calling it too late — inside a loop that re-enumerates a deferred query built from a changing source — can silently produce inconsistent results. Always be intentional about when a query materializes.
- dotnet new, restore, build, test, run, and publish are the core CLI verbs for everyday development.
- LINQ queries on IEnumerable<T> are deferred until enumerated via foreach, ToList(), or Count().
- Dictionary<TKey,TValue> gives average O(1) key lookup versus List<T>.Contains()'s O(n) scan.
- IConfiguration layers appsettings.json, environment-specific JSON, environment variables, and CLI args in that override order.
- The strongly-typed options pattern binds a config section to a POCO via Configure<T> and IOptions<T>.
- IOptionsSnapshot<T> supports per-request reload of configuration values, unlike IOptions<T>.
- Use dotnet ef migrations add and dotnet ef database update to manage EF Core schema changes.
Practice what you learned
1. Which CLI command scaffolds a brand-new ASP.NET Core Web API project?
2. When does a LINQ query built with .Where() and .Select() on an IEnumerable<T> actually execute?
3. Why is List<T>.Contains() a common performance pitfall for frequent membership checks?
4. In ASP.NET Core's configuration system, which source generally overrides appsettings.json in production?
5. What does the strongly-typed options pattern (Configure<T> + IOptions<T>) provide over raw configuration["Key"] access?
Was this page helpful?
You May Also Like
.NET Core Interview Questions
A focused review of the .NET Core concepts most commonly probed in technical interviews: the CLR, async/await, and dependency injection.
Unit Testing in .NET
How to write fast, isolated unit tests for .NET applications using xUnit and Moq, and the practices that keep a test suite trustworthy.
.NET Versioning and LTS Releases
How .NET's release cadence, LTS vs STS support tiers, and target framework monikers work, and how to plan upgrades around them.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics