Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 750 Bytes

CustomDtoSource.md

File metadata and controls

27 lines (23 loc) · 750 Bytes

Example 1

Get DTOs from application service

public class MyProjectRelatedDtoLoaderProfile : RelatedDtoLoaderProfile
{
    public MyProjectRelatedDtoLoaderProfile(IServiceProvider serviceProvider) : base(serviceProvider)
    {
        CreateRule<ProductDto>(async ids =>
        {
            var dtos = new List<ProductDto>();
            
            using (var scope = serviceProvider.CreateScope())
            {
                var productAppService = scope.ServiceProvider.GetService<IProductAppService>();
                
                foreach (var id in ids)
                {
                    dtos.Add(await productAppService.GetAsync(id));
                }
            }

            return dtos;
        });
    }
}