|
|
@ -1,9 +1,12 @@ |
|
|
|
using Autofac; |
|
|
|
using Autofac.Core; |
|
|
|
using FluentValidation; |
|
|
|
using MediatR; |
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; |
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Decorators; |
|
|
|
using Ordering.API.Application.Decorators; |
|
|
|
using Ordering.API.Application.DomainEventHandlers.OrderStartedEvent; |
|
|
|
using Ordering.API.Application.Validations; |
|
|
|
using Ordering.Domain.Events; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
@ -24,11 +27,17 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof |
|
|
|
.Where(i => i.IsClosedTypeOf(typeof(IAsyncRequestHandler<,>))) |
|
|
|
.Select(i => new KeyedService("IAsyncRequestHandler", i))); |
|
|
|
|
|
|
|
// Register all the Domain Event Handler classes (they implement IAsyncNotificationHandler<>) in assembly holding the Domain Events
|
|
|
|
// Register all the event classes (they implement IAsyncNotificationHandler) in assembly holding the Commands
|
|
|
|
builder.RegisterAssemblyTypes(typeof(ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler).GetTypeInfo().Assembly) |
|
|
|
.As(o => o.GetInterfaces() |
|
|
|
.Where(i => i.IsClosedTypeOf(typeof(IAsyncNotificationHandler<>))) |
|
|
|
.Select(i => new KeyedService("IAsyncNotificationHandler", i))); |
|
|
|
|
|
|
|
builder |
|
|
|
.RegisterAssemblyTypes(typeof(ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler).GetTypeInfo().Assembly) |
|
|
|
.Where(t => t.IsClosedTypeOf(typeof(IAsyncNotificationHandler<>))) |
|
|
|
.AsImplementedInterfaces(); |
|
|
|
.RegisterAssemblyTypes(typeof(CreateOrderCommandValidator).GetTypeInfo().Assembly) |
|
|
|
.Where(t => t.IsClosedTypeOf(typeof(IValidator<>))) |
|
|
|
.AsImplementedInterfaces(); |
|
|
|
|
|
|
|
|
|
|
|
builder.Register<SingleInstanceFactory>(context => |
|
|
|
{ |
|
|
@ -44,9 +53,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof |
|
|
|
return t => (IEnumerable<object>)componentContext.Resolve(typeof(IEnumerable<>).MakeGenericType(t)); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.RegisterGenericDecorator(typeof(LogDecorator<,>), |
|
|
|
typeof(IAsyncRequestHandler<,>), |
|
|
|
"IAsyncRequestHandler"); |
|
|
|
"IAsyncRequestHandler") |
|
|
|
.Keyed("handlerDecorator", typeof(IAsyncRequestHandler<,>)); |
|
|
|
|
|
|
|
builder.RegisterGenericDecorator(typeof(ValidatorDecorator<,>), |
|
|
|
typeof(IAsyncRequestHandler<,>), |
|
|
|
fromKey: "handlerDecorator"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |