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.
Singleton, Factory Method, Abstract Factory, Builder, Prototype and Object Pool, and how DI lifetimes, factories and pooling replace or implement them in .NET 10.
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.