Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: builder.Services.AddCors(options => { options.AddPolicy("MyPolicy", policy => { policy.WithOrigins(" .AllowAnyHeader() .AllowAnyMethod(); }); }); app.UseCors("MyPolicy"); Must…
Short answer: Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilter)); }); Advanced Level Example code Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilt…
Short answer: wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI) wait _next(conte…
Short answer: execution time) Example custom middleware to measure time: public class TimingMiddleware Example code { private readonly RequestDelegate _next; public TimingMiddleware(RequestDelegate next) => _next = ne…
Short answer: Caching expensive requests where model binding is unnecessary. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for ever…
Short answer: Dependency Injection (DI) is a design pattern that allows you to inject dependencies (services) into classes instead of hard-coding them. Real-world example (ShopNest) ShopNest registers AppDbContext as Sco…
Short answer: Filters specifically built for Minimal APIs (introduced in ASP.NET Core 7). Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same…
Short answer: ✅ Capabilities: Constructor injection Lifetime management (Transient, Scoped, Singleton) Supports IEnumerable<T>, IServiceProvider, and open generics ⚠ Limitations: No support for named registrations…
Short answer: Used for filters that require custom instantiation logic. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every con…
Short answer: Lifetime Description Use Case Example Transient New instance every time Lightweight stateless services Scoped One instance per request Database context, UoW Singleto One instance for the app's lifetime Logg…
Short answer: Lower order executes first on entry but last on exit—like nested layers. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rul…
Short answer: public void ConfigureServices(IServiceCollection services) { services.AddTransient<IMyService, MyService>(); services.AddScoped<IRepository, Repository>(); services.AddSingleton<ILoggerServic…
Short answer: Use a mocked HttpContext and assert on changes. Real-world example (ShopNest) ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.…
Short answer: Controllers: Constructor injection Razor Pages: Constructor injection in PageModel Middleware: Inject via constructor or use IApplicationBuilder.ApplicationServices Real-world example (ShopNest) ShopNest pi…
Short answer: Use [SkipFilter] custom attribute or exclude via filter predicates. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for…
Short answer: Constructor Injection: Supported and preferred in ASP.NET Core. Property Injection: Not supported natively in built-in DI; can be achieved via custom logic or 3rd-party containers. ✅ Use constructor injecti…
Short answer: No. But middleware can replace some filter use cases. Say this in the interview Define — one clear sentence (the short answer above). Example — relate it to a project like ShopNest or your real work. Trade-…
Short answer: IServiceProvider: Resolves services manually. IServiceScopeFactory: Creates a new DI scope (useful for background tasks). using (var scope = serviceScopeFactory.CreateScope()) Example code { var scopedServi…
Short answer: Middleware logs incoming requests; action filter logs controller-level execution. Real-world example (ShopNest) ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints…
Short answer: Scoped services are tied to the HTTP request lifecycle. In background tasks, you must manually create a scope using IServiceScopeFactory to resolve scoped services safely. Real-world example (ShopNest) Shop…
Short answer: Mixing sync &amp; async can cause deadlocks. Prefer async filters. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule…
Short answer: To replace: services.AddSingleton<IService, CustomImplementation>(); To remove: var descriptor = services.First(x => x.ServiceType == typeof(IMyService)); services.Remove(descriptor); Real-world ex…
Short answer: Yes—but avoid heavy operations that run per action. Real-world example (ShopNest) ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading b…
Short answer: IOptionsMonitor) IOptions<T>: For singleton/config services. IOptionsSnapshot<T>: Scoped; updates per request. IOptionsMonitor<T>: Singleton; can react to config changes. services.Configur…
Short answer: Use IOptions or DI into constructor. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller. Say this in…
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: builder.Services.AddCors(options => { options.AddPolicy("MyPolicy", policy => { policy.WithOrigins(" .AllowAnyHeader() .AllowAnyMethod(); }); }); app.UseCors("MyPolicy"); Must be placed before routing/endpoints.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilter)); }); Advanced Level
Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilter)); }); Advanced Level
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI) wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency… Injection (DI) wait… _next(context); sw.Stop(); Console.WriteLine($"Request took…
{sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI) wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency… Injection (DI)
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: execution time) Example custom middleware to measure time: public class TimingMiddleware
{
private readonly RequestDelegate _next;
public TimingMiddleware(RequestDelegate next) => _next = next; public async Task InvokeAsync(HttpContext context)
{
var sw = Stopwatch.StartNew();
await _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); }
} Register: app.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI)
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Caching expensive requests where model binding is unnecessary.
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Dependency Injection (DI) is a design pattern that allows you to inject dependencies (services) into classes instead of hard-coding them.
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Filters specifically built for Minimal APIs (introduced in ASP.NET Core 7).
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: ✅ Capabilities: Constructor injection Lifetime management (Transient, Scoped, Singleton) Supports IEnumerable<T>, IServiceProvider, and open generics ⚠ Limitations: No support for named registrations Limited property injection Basic feature set compared to Autofac or other 3rd-party containers
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Used for filters that require custom instantiation logic.
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Lifetime Description Use Case Example Transient New instance every time Lightweight stateless services Scoped One instance per request Database context, UoW Singleto One instance for the app's lifetime Logging, Config access
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Lower order executes first on entry but last on exit—like nested layers.
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: public void ConfigureServices(IServiceCollection services) { services.AddTransient<IMyService, MyService>(); services.AddScoped<IRepository, Repository>(); services.AddSingleton<ILoggerService, LoggerService>(); }
public void ConfigureServices(IServiceCollection services)
{ services.AddTransient<IMyService, MyService>(); services.AddScoped<IRepository, Repository>(); services.AddSingleton<ILoggerService, LoggerService>(); }
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Use a mocked HttpContext and assert on changes.
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Controllers: Constructor injection Razor Pages: Constructor injection in PageModel Middleware: Inject via constructor or use IApplicationBuilder.ApplicationServices
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Use [SkipFilter] custom attribute or exclude via filter predicates.
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Constructor Injection: Supported and preferred in ASP.NET Core. Property Injection: Not supported natively in built-in DI; can be achieved via custom logic or 3rd-party containers. ✅ Use constructor injection for immutability and clarity.
Constructor Injection: Supported and preferred in ASP.NET Core. Property Injection: Not supported natively in built-in DI; can be achieved via custom logic or 3rd-party containers. ✅ Use constructor injection for immutability and clarity.
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: No. But middleware can replace some filter use cases.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: IServiceProvider: Resolves services manually. IServiceScopeFactory: Creates a new DI scope (useful for background tasks). using (var scope = serviceScopeFactory.CreateScope())
{
var scopedService = scope.ServiceProvider.GetRequiredService<IMyScopedService>(); }
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Middleware logs incoming requests; action filter logs controller-level execution.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Scoped services are tied to the HTTP request lifecycle. In background tasks, you must manually create a scope using IServiceScopeFactory to resolve scoped services safely.
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Mixing sync & async can cause deadlocks. Prefer async filters.
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: To replace: services.AddSingleton<IService, CustomImplementation>(); To remove: var descriptor = services.First(x => x.ServiceType == typeof(IMyService)); services.Remove(descriptor);
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Yes—but avoid heavy operations that run per action.
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: IOptionsMonitor) IOptions<T>: For singleton/config services. IOptionsSnapshot<T>: Scoped; updates per request. IOptionsMonitor<T>: Singleton; can react to config changes. services.Configure<MySettings>(Configuration.GetSection("MySettings" ));
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Use IOptions or DI into constructor.
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.