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:
2026-07-05 04:36:46 +02:00
parent db38740139
commit c84e29ed54
5 changed files with 47 additions and 69 deletions
@@ -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;
}