Problem statement
Complete FeatureSettingsService so runtime configuration changes are honoured without restarting the host. The app exposes a Feature configuration section (welcome message, discount percent, and max items). Reading the settings, updating them, and quoting a discounted price must all reflect the current configuration — an update made through PUT /settings must be visible on the very next GET /settings and GET /quote. The trick is resolving options with IOptionsSnapshot<FeatureOptions> (recomputed per request) rather than IOptions<FeatureOptions> (cached once at startup). Validation lives in the service layer, not the controller.
Seeded Configuration
appsettings.json seeds the Feature section:
{
"Feature": {
"WelcomeMessage": "Welcome",
"DiscountPercent": 10,
"MaxItems": 5
}
}
API Endpoints to Implement
GET /settings— return the current feature settings.PUT /settings— validate and apply new settings, then reload configuration so the change is observed without a restart. Invalid input (blank welcome message, discount outside0..100, ormaxItems < 1) returns400.GET /quote?price=— apply the current discount toprice(clamped at0). Aprice <= 0(including a missing value) returns400.
Sample Requests & Responses
Expand to view details on sample requests and responses for each endpoint.
GET /settings
Response code: 200
{
"welcomeMessage": "Welcome",
"discountPercent": 10,
"maxItems": 5
}
PUT /settings
Request:
{
"welcomeMessage": "Hello there",
"discountPercent": 25,
"maxItems": 8
}
Response code: 200
{
"welcomeMessage": "Hello there",
"discountPercent": 25,
"maxItems": 8
}
GET /quote?price=100 (after the update above)
Response code: 200
{
"price": 100,
"discountPercent": 25,
"finalPrice": 75
}
PUT /settings with discountPercent = 150
Response code: 400
GET /quote (missing price)
Response code: 400
