How is the middleware pipeline configured (in Program.cs / Startup.cs)?
Short answer: var app = builder.Build(); app.UseMiddleware<YourMiddleware>(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.Run(); In older versions (e.g., .NET Core 3.1), Startup.cs is used: public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseMiddleware<YourMiddleware>(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
Example code
In ASP.NET Core 6+ (minimal hosting model), middleware is added in Program.cs: var builder = WebApplication.CreateBuilder(args);
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-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png