refactor(di): add AddApplication entry point and generic AddValidatedOptions
- 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.
This commit is contained in:
@@ -5,7 +5,6 @@ using Microsoft.Extensions.Options;
|
||||
using Musify.Application.Configuration;
|
||||
using Musify.Infrastructure.Configuration;
|
||||
using Musify.Infrastructure.Jobs;
|
||||
using Musify.Application.Services;
|
||||
using Musify.Application.Contracts;
|
||||
|
||||
namespace Musify.Infrastructure.Services
|
||||
@@ -46,15 +45,7 @@ namespace Musify.Infrastructure.Services
|
||||
|
||||
public static IServiceCollection AddUploadIntentConfiguration(this IServiceCollection serviceDescriptors, IConfiguration configuration)
|
||||
{
|
||||
serviceDescriptors
|
||||
.AddOptionsWithValidateOnStart<UploadIntentConfiguration>()
|
||||
.Bind(configuration.GetRequiredSection(UploadIntentConfiguration.SectionName))
|
||||
.ValidateDataAnnotations();
|
||||
|
||||
serviceDescriptors.AddSingleton(serviceProvider =>
|
||||
serviceProvider.GetRequiredService<IOptions<UploadIntentConfiguration>>().Value);
|
||||
|
||||
serviceDescriptors.AddScoped<UploadIntentValidator>();
|
||||
serviceDescriptors.AddValidatedOptions<UploadIntentConfiguration>(configuration, UploadIntentConfiguration.SectionName);
|
||||
|
||||
return serviceDescriptors;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user