-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
60 lines (58 loc) · 2.59 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
60 lines (58 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Directory;
using Grand.Domain.Localization;
using Grand.Domain.Media;
using Grand.Domain.Shipping;
using Grand.Domain.Stores;
using Grand.Domain.Vendors;
using Grand.Module.Api.DTOs.Catalog;
using Grand.Module.Api.DTOs.Common;
using Grand.Module.Api.DTOs.Customers;
using Grand.Module.Api.DTOs.Shipping;
using Grand.Module.Api.Queries.Handlers.Common;
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
namespace Grand.Module.Api.Infrastructure.Extensions
{
public static class ServiceCollectionExtensions
{
public static void RegisterRequestHandler(this IServiceCollection services)
{
var handlerTypes = new (Type dto, Type entity)[]
{
(typeof(CountryDto), typeof(Country)),
(typeof(CurrencyDto), typeof(Currency)),
(typeof(BrandDto), typeof(Brand)),
(typeof(CategoryDto), typeof(Category)),
(typeof(CollectionDto), typeof(Collection)),
(typeof(ProductAttributeDto), typeof(ProductAttribute)),
(typeof(ProductDto), typeof(Product)),
(typeof(SpecificationAttributeDto), typeof(SpecificationAttribute)),
(typeof(WarehouseDto), typeof(Warehouse)),
(typeof(ShippingMethodDto), typeof(ShippingMethod)),
(typeof(PickupPointDto), typeof(PickupPoint)),
(typeof(DeliveryDateDto), typeof(DeliveryDate)),
(typeof(VendorDto), typeof(Vendor)),
(typeof(CustomerGroupDto), typeof(CustomerGroup)),
(typeof(StoreDto), typeof(Store)),
(typeof(LanguageDto), typeof(Language)),
(typeof(PictureDto), typeof(Picture)),
(typeof(LayoutDto), typeof(BrandLayout)),
(typeof(LayoutDto), typeof(CollectionLayout)),
(typeof(LayoutDto), typeof(CategoryLayout)),
(typeof(LayoutDto), typeof(ProductLayout))
};
foreach (var (dto, entity) in handlerTypes)
{
var requestHandlerType = typeof(IRequestHandler<,>).MakeGenericType(
typeof(GetGenericQuery<,>).MakeGenericType(dto, entity),
typeof(IQueryable<>).MakeGenericType(dto)
);
var handlerImplementationType = typeof(GetGenericQueryHandler<,>).MakeGenericType(dto, entity);
services.AddScoped(requestHandlerType, handlerImplementationType);
}
}
}
}