- Add Musify.Application.AddApplication(services, config) as the layer's DI entry point: registers Mediator, UploadIntentValidator and all app configs - Collapse the 5 near-identical AddXConfiguration methods into a single generic AddValidatedOptions<T>(config, section) - Move UploadIntentValidator registration out of Infrastructure into the Application layer (fixes layering leak); Infra config binding now uses the generic helper - Api calls AddApplication; Worker uses AddValidatedOptions for its configs Build: 0 warnings, 0 errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
26 lines
750 B
C#
26 lines
750 B
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Musify.Application.Configuration;
|
|
|
|
public static class ConfigurationDependencyInjection
|
|
{
|
|
public static IServiceCollection AddValidatedOptions<T>(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
string sectionName)
|
|
where T : class
|
|
{
|
|
services
|
|
.AddOptionsWithValidateOnStart<T>()
|
|
.Bind(configuration.GetRequiredSection(sectionName))
|
|
.ValidateDataAnnotations();
|
|
|
|
services.AddSingleton(serviceProvider =>
|
|
serviceProvider.GetRequiredService<IOptions<T>>().Value);
|
|
|
|
return services;
|
|
}
|
|
}
|