1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.
The GoF creational, structural and behavioural patterns and the enterprise patterns used in modern .NET 10 services, with the judgement to know when a pattern helps and when it is ceremony.
What design patterns are, the three GoF categories with .NET framework examples (DI lifetimes, IHttpClientFactory, StringBuilder, Stream wrappers, DelegatingHandler, IEnumerable, middleware), and when a pattern is ceremony.
Singleton intent, three thread-safe C# implementations (static readonly with type initialiser guarantees, Lazy<T> with ExecutionAndPublication, double-checked locking with volatile), their pitfalls, and why the DI singleton lifetime replaces the hand-rolled pattern.
Captive dependencies (a singleton holding a scoped or transient service), the data-leak and thread-safety symptoms, ValidateScopes and ValidateOnBuild, and fixes with IServiceScopeFactory, lifetime changes and IHttpClientFactory.
Simple factory vs GoF Factory Method (subclass decides, DbConnection.CreateCommand) vs Abstract Factory (families of related objects, DbProviderFactory, DbDataSource), IHttpClientFactory and ILoggerFactory, and when DI factory delegates replace them.
Run-time implementation selection in .NET 10 DI: keyed services (AddKeyedScoped, [FromKeyedServices], GetRequiredKeyedService), Func factory delegates, an IEnumerable-to-FrozenDictionary resolver, unknown-key handling, testing, and keeping IServiceProvider at the composition root.
GoF Builder vs fluent builder, framework builders (StringBuilder, UriBuilder, SqlConnectionStringBuilder, WebApplicationBuilder, HostApplicationBuilder, DbContextOptionsBuilder, ResiliencePipelineBuilder), test data builders, validation in Build(), and when required/init initialisers replace a builder.
Prototype intent, shallow vs deep copy, MemberwiseClone semantics, ICloneable's ambiguity, records and with (shallow copy constructor), deep-copy options, JsonSerializerOptions and HttpRequestMessage cloning, and EF Core PropertyValues.Clone.
Object Pool in .NET 10: Microsoft.Extensions.ObjectPool (policies, IResettable, MaximumRetained), ArrayPool<T>.Shared, AddDbContextPool, ADO.NET connection pooling, reset and use-after-return bugs, why pooling can be slower than gen0 allocation, and measuring with BenchmarkDotNet and dotnet-counters.
Code review of creational anti-patterns: racy static singleton, unsynchronised Dictionary, HttpClient per call, DbContext held by a singleton, sync-over-async, switch factory with silent fallback and hard-coded secret; rewrite with DI lifetimes, typed HttpClient, HybridCache, keyed or options-driven provider selection.
Adapter intent, object vs class adapter, wrapping a vendor SDK (Stripe.net) behind a domain interface, translating units, types and exceptions, .NET examples (StreamReader, TaskCompletionSource, Serilog's ILoggerProvider), and keeping business logic out of adapters.
Decorator intent and structure, composition-based stacking, .NET examples (BufferedStream, GZipStream, CryptoStream, DelegatingHandler pipelines), registering decorators with factory delegates, keyed services or Scrutor, ordering, and decorators vs inheritance, middleware and AOP.
Coding a HybridCache caching decorator: GetOrCreateAsync with keys and TTLs, stampede protection, invalidation on writes (RemoveAsync, tags), not caching nulls or failures by accident, tenant-aware keys, immutable cached types, registration via factory delegate, keyed services and Scrutor, and tests.
Facade intent (a simple entry point over a subsystem), .NET examples (File.ReadAllTextAsync, HttpClient, JsonSerializer, DbContext), an order-checkout facade, facade vs god service vs application service, and keeping facades thin.
Proxy intent and kinds (virtual, remote, protection, smart reference), EF Core lazy-loading proxies (virtual navigations, Castle, N+1, disposed-context errors), DispatchProxy for interfaces (and its AOT limits), Castle DynamicProxy interceptors, generated HTTP/gRPC clients, and the cost of invisible behaviour.
Composite intent (part-whole trees with a uniform interface), leaf vs composite, a permission-group or rule tree in C#, .NET examples (CompositeFileProvider, CompositeChangeToken, expression trees), recursion depth and StackOverflowException, cycle detection, and storing hierarchies (recursive CTE, hierarchyid).
Bridge intent (separate an abstraction from its implementation so both vary independently), avoiding M×N class explosions, notification types × channels in C#, ILogger over ILoggerProvider and HttpClient over HttpMessageHandler, and Bridge vs Adapter vs Strategy.
A comparison of the four wrapper patterns: Adapter (converts an interface), Decorator (same interface, adds behaviour), Proxy (same interface, controls access and lifecycle), Facade (new simpler interface over many classes), with .NET examples, a decision guide, and why mislabelling leads to misplaced logic such as duplicate retries.
Flyweight intent (share immutable intrinsic state, pass extrinsic state in), string literal interning and string.Intern's process-lifetime cost, custom string pools, cached instances (Task.CompletedTask, Array.Empty, CultureInfo), SearchValues and FrozenDictionary as precomputed shared state, and measuring with dotnet-gcdump and dotnet-counters.
Debugging decorator and DelegatingHandler ordering: fallbacks cached by a cache decorator, timeouts and retries layered in the wrong order or twice (custom handler plus AddStandardResilienceHandler), duplicate logging from double registration; inspecting IServiceCollection descriptors, the resolved decorator chain, handler order, and OpenTelemetry span nesting; tests that lock the order.
Strategy intent and structure, replacing growing switch statements with interchangeable algorithms, .NET examples (IComparer<T>, IEqualityComparer<T>, StringComparer, JsonNamingPolicy), selecting strategies via IEnumerable<T>, a dictionary or keyed services, delegates as one-method strategies, and when a switch is still clearer.