using ECMJobRunner.Application.DEXJob.Commands.Behaviors; using MediatR; using Microsoft.Extensions.DependencyInjection; using ReC.Client; using System.Reflection; namespace ECMJobRunner.Application { /// /// Extension methods for configuring Application layer services /// public static class DependencyInjection { /// /// Adds Application layer services to the dependency injection container /// Registers MediatR, pipeline behaviors, and AutoMapper /// /// The service collection /// The service collection for chaining public static IServiceCollection AddJobRunnerServices(this IServiceCollection services, string recClientApiUrl) { var assembly = Assembly.GetExecutingAssembly(); // Register MediatR with all handlers from this assembly #if NET48 services.AddMediatR(assembly); #else services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(assembly)); #endif // Register AutoMapper with all profiles from this assembly services.AddAutoMapper(assembly); services.AddRecClient(recClientApiUrl, opt => { opt.LogSuccessfulRequests = true; }); // Register pipeline behaviors in execution order // Order matters: MainQuery -> CheckQuery -> ReCRequest services.AddTransient(typeof(IPipelineBehavior<,>), typeof(MainQueryExecutionBehavior<,>)); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CheckQueryExecutionBehavior<,>)); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ReCRequestExecutionBehavior<,>)); return services; } } }