What are good practices for ASP.NET Core application structure and configuration?
Quick Interview Answer
Detailed Explanation
A maintainable ASP.NET Core application should keep responsibilities separated and make environment-specific behavior explicit.
Useful practices include keeping Program.cs focused on application composition, using strongly typed options for related settings, validating critical options at startup, keeping secrets outside source control, using environment-specific configuration only where appropriate, and registering services through clear dependency injection abstractions.
Larger solutions should separate domain/business logic from infrastructure concerns, avoid putting business logic in controllers or Program.cs, and keep configuration keys centralized through options classes. The exact folder or project structure can vary; clear dependencies and maintainable boundaries are more important than following one rigid template.
Code Example
builder.Services
.AddOptions<StorageSettings>()
.Bind(builder.Configuration.GetSection("Storage"))
.ValidateDataAnnotations()
.ValidateOnStart();
builder.Services.AddApplicationServices();
builder.Services.AddInfrastructure(builder.Configuration);