Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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 & 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…
Short answer: there Use IHostedService or BackgroundService for tasks that run in the background. Services are injected via constructor. Scoped services must use IServiceScopeFactory. Real-world example (ShopNest) ShopNe…
Short answer: When exceptions must be caught outside MVC (e.g., authorization failures). Say this in the interview Define — one clear sentence (the short answer above). Example — relate it to a project like ShopNest or y…
Short answer: IConfiguration is automatically registered and injected via constructor. public MyService(IConfiguration config) Example code { var key = config["MyKey"]; } Real-world example (ShopNest) A ShopNes…
Short answer: dd custom validation and authorization filters using .AddEndpointFilter(). Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same r…
Short answer: ASP.NET Core provides structured logging via ILogger<T>. public class MyService Example code { private readonly ILogger<MyService> _logger; public MyService(ILogger<MyService> logger) =>…
Short answer: Yes—result filters can wrap or modify responses. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.…
Short answer: Occurs when two services depend on each other directly or indirectly. 🛠 Fix: Refactor to remove circular reference Use Lazy<T> or factory injection Split responsibilities Real-world example (ShopNest…
Short answer: A filter that tracks performance of controller actions: public class ProfilingFilter : IAsyncActionFilter Example code { public async Task OnActionExecutionAsync( ActionExecutingContext context, ActionExecu…
Short answer: Use a mocking framework like Moq: var mockService = new Mock<IMyService>(); mockService.Setup(s => s.Get()).Returns("test"); var controller = new MyController(mockService.Object); Mocking…
Short answer: MVC (Model-View-Controller) is a pattern for organizing code into: Model: Data and business logic View: UI rendering Controller: Input handling and app flow Built on a modular, cross-platform framework. Use…
Short answer: How does it differ from MVC in “older” ASP.NET? MVC (Model-View-Controller) is a pattern for organizing code into: Model: Data and business logic View: UI rendering Controller: Input handling and app flow B…
Short answer: SP.NET Core 2.0. Each .cshtml file has an associated PageModel class (like a view + controller combined). Best for simple UI-focused apps or CRUD pages. ✅ Use Razor Pages for: Simpler, page-focused apps ✅ U…
Short answer: When to use Razor Pages instead of MVC? Razor Pages is a page-based programming model introduced in ASP.NET Core 2.0. Each .cshtml file has an associated PageModel class (like a view + controller combined).…
Short answer: MVC Routing: Uses attribute routing or conventional routing. Example code endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); Razor Pages R…
Short answer: }"); Razor Pages Routing: Based on folder structure. URL /Products/Edit maps to /Pages/Products/Edit.cshtml. Real-world example (ShopNest) A ShopNest checkout request flows through middleware, hits a m…
Short answer: view or JSON). View: .cshtml file that renders HTML. View Component: Reusable mini-views with logic (like partials but with code-behind). Real-world example (ShopNest) A ShopNest checkout request flows thro…
Short answer: Controller: Handles HTTP requests. Action Method: A method in the controller that returns a result (like a view or JSON). View: .cshtml file that renders HTML. View Component: Reusable mini-views with logic…
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.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: there Use IHostedService or BackgroundService for tasks that run in the background. Services are injected via constructor. Scoped services must use IServiceScopeFactory.
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: When exceptions must be caught outside MVC (e.g., authorization failures).
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: IConfiguration is automatically registered and injected via constructor. public MyService(IConfiguration config)
{
var key = config["MyKey"];
}
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: dd custom validation and authorization filters using .AddEndpointFilter().
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: ASP.NET Core provides structured logging via ILogger<T>. public class MyService
{
private readonly ILogger<MyService> _logger;
public MyService(ILogger<MyService> logger) => _logger = logger;
public void DoSomething() => _logger.LogInformation("Action performed"); }
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: Yes—result filters can wrap or modify responses.
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: Occurs when two services depend on each other directly or indirectly. 🛠 Fix: Refactor to remove circular reference Use Lazy<T> or factory injection Split responsibilities
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: A filter that tracks performance of controller actions: public class ProfilingFilter : IAsyncActionFilter
{
public async Task OnActionExecutionAsync( ActionExecutingContext context, ActionExecutionDelegate next) {
var sw = Stopwatch.StartNew();
var result = await next(); sw.Stop(); Console.WriteLine($"Action took {sw.ElapsedMilliseconds}ms"); }
}
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: Use a mocking framework like Moq: var mockService = new Mock<IMyService>(); mockService.Setup(s => s.Get()).Returns("test"); var controller = new MyController(mockService.Object); Mocking helps isolate the unit of work and test behavior independently. MVC & Razor Pages
Use a mocking framework like Moq: var mockService = new Mock<IMyService>();
mockService.Setup(s => s.Get()).Returns("test");
var controller = new MyController(mockService.Object); Mocking helps isolate the unit of work and test behavior independently. MVC & Razor Pages
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: MVC (Model-View-Controller) is a pattern for organizing code into: Model: Data and business logic View: UI rendering Controller: Input handling and app flow Built on a modular, cross-platform framework. Uses dependency injection by default. Unified Web API + MVC pipeline. Lightweight and middleware-based request processing.
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: How does it differ from MVC in “older” ASP.NET? MVC (Model-View-Controller) is a pattern for organizing code into: Model: Data and business logic View: UI rendering Controller: Input handling and app flow Built on a modular, cross-platform framework. Uses dependency injection by default. Unified Web API + MVC pipeline. Lightweight and middleware-based request processing.
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: SP.NET Core 2.0. Each .cshtml file has an associated PageModel class (like a view + controller combined). Best for simple UI-focused apps or CRUD pages. ✅ Use Razor Pages for: Simpler, page-focused apps ✅ Use MVC for: Complex, controller-based routing or large, structured apps
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: When to use Razor Pages instead of MVC? Razor Pages is a page-based programming model introduced in ASP.NET Core 2.0. Each .cshtml file has an associated PageModel class (like a view + controller combined). Best for simple UI-focused apps or CRUD pages. ✅ Use Razor Pages for: Simpler, page-focused apps ✅ Use MVC for: Complex, controller-based routing or large, structured apps
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: MVC Routing: Uses attribute routing or conventional routing.
endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); Razor Pages Routing: Based on folder structure. URL /Products/Edit maps to /Pages/Products/Edit.cshtml.
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: }"); Razor Pages Routing: Based on folder structure. URL /Products/Edit maps to /Pages/Products/Edit.cshtml.
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: view or JSON). View: .cshtml file that renders HTML. View Component: Reusable mini-views with logic (like partials but with code-behind).
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: Controller: Handles HTTP requests. Action Method: A method in the controller that returns a result (like a view or JSON). View: .cshtml file that renders HTML. View Component: Reusable mini-views with logic (like partials but with code-behind).
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.