feat(application): add dependency injection configuration & documentation
- Implement DependencyInjection.cs with AddApplication() extension
- Register MediatR with assembly scanning
- Register pipeline behaviors in execution order:
1. CheckQueryExecutionBehavior
2. MainQueryExecutionBehavior
3. ReCRequestExecutionBehavior
- Conditional package versions (MediatR 9.0.0/12.4.1)
- Add comprehensive README.md
- Architecture overview & CQRS pipeline flow
- Configuration guide (DexJobOptions, ErrorAction)
- DI setup examples (AddApplication, AddInfrastructure)
- Exception handling patterns
- Multi-targeting notes & troubleshooting
- Update project file with MediatR.Extensions.DependencyInjection
This commit is contained in:
39
ECMJobRunner.Application/DependencyInjection.cs
Normal file
39
ECMJobRunner.Application/DependencyInjection.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using ECMJobRunner.Application.Behaviors;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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>
|
||||
/// <returns>The service collection for chaining</returns>
|
||||
public static IServiceCollection AddApplication(this IServiceCollection services)
|
||||
{
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user