Files
ECMJobRunner/ECMJobRunner.Application/DependencyInjection.cs
TekH f75524f85d feat(config): add DexJobOptions configuration system and update placeholder pattern
- Add SectionName constant to DexJobOptions
- Update placeholder pattern to {#INT#BATCH_ID}
- Add DexJob configuration section to appsettings.json
- Add IConfiguration parameter to DependencyInjection for options binding
- Add Microsoft.Extensions.Options.ConfigurationExtensions package for .NET Framework 4.8
- Improve code documentation and move class into namespace
2026-08-04 16:33:26 +02:00

56 lines
2.3 KiB
C#

using ECMJobRunner.Application.Common.Options;
using ECMJobRunner.Application.Profiles.Commands.Behaviors;
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ReC.Client;
using System.Reflection;
namespace ECMJobRunner.Application
{
/// <summary>
/// Extension methods for configuring Application layer services
/// </summary>
public static class DependencyInjection
{
/// <summary>
/// Adds Application layer services to the dependency injection container
/// Registers MediatR, pipeline behaviors, and AutoMapper
/// </summary>
/// <param name="services">The service collection</param>
/// <param name="recClientApiUrl">The base URL for the ReC client API</param>
/// <param name="configuration">The application configuration</param>
/// <returns>The service collection for chaining</returns>
public static IServiceCollection AddJobRunnerServices(this IServiceCollection services, string recClientApiUrl, IConfiguration configuration)
{
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;
});
// Configure DexJobOptions from appsettings.json
services.Configure<DexJobOptions>(configuration.GetSection(DexJobOptions.SectionName));
// Register pipeline behaviors in execution order
// Order matters: MainQuery -> CheckQuery -> ReCRequest
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(JobExceptionHandlingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(MainQueryExecutionBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CheckQueryExecutionBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ReCRequestExecutionBehavior<,>));
return services;
}
}
}