ASP.NET Core Interview Question #38
What is WebApplicationBuilder?
Application Structure & Configuration Junior Beginner
Quick Interview Answer
WebApplicationBuilder is the object created by WebApplication.CreateBuilder(args). It is used to configure services and application infrastructure before the application is built.
Detailed Explanation
WebApplicationBuilder is the object created by WebApplication.CreateBuilder(args). It is used to configure services and application infrastructure before the application is built.
Its important members include Services for dependency injection registrations, Configuration for application settings, Environment for hosting environment information, Logging for logging providers, and Host/WebHost for lower-level hosting configuration.
After registrations are complete, Build() produces a WebApplication. Service registrations should generally be completed before Build() is called.
Code Example
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddScoped<IOrderService, OrderService>();
builder.Logging.AddConsole();
var app = builder.Build();