در یک پروژه قست دارم ترکیب از gRPC و Rest API داشته باشم
لایه های زیر را ایجاد کرده ام
ProductCatalogService.Application
ProductCatalogService.Domin
ProductCatalogService.DataAccess
ProductCatalogService.WebService
ProductCatalogService.GrpcService => ASP.Net Core gRPC Service
در لایه Application
namespace ProductCatalogService.Application.Mapping
{
public class MappingProfile : Profile
{
public MappingProfile()
{...}
در لایه GrpcService
namespace ProductCatalogService.GrpcService.GrpcMapping
{
public class GrpcMappingProfile : Profile
{
public GrpcMappingProfile()
{
CreateMap<GetAllResponse, CategoryDto>().ReverseMap();
}
در program.cs لایه WebService
builder.Services.AddAutoMapper(typeof(GrpcMappingProfile).Assembly, typeof(MappingProfile).Assembly);
در program.cs لایه GrpcService
builder.Services.AddAutoMapper(typeof(GrpcMappingProfile).Assembly, typeof(MappingProfile).Assembly);
در category.proto
syntax = "proto3";
option csharp_namespace = "ProductCatalogService.GrpcService.Protos";
service CategoryProtoService {
rpc GetAllCategories (Empty) returns (GetAllCategoriesResponse);
}
message Empty {}
message GetAllResponse {
int32 id = 1;
string name = 2;
}
message GetAllCategoriesResponse {
repeated GetAllResponse categories = 1;
}
در mapping زیر
namespace ProductCatalogService.WebApi.Clients;
public class CategoryGrpcClient
{
public async Task<IEnumerable<CategoryDto>> GetAllCategoriesAsync()
{
var response = await _client.GetAllCategoriesAsync(new Empty());
return _mapper.Map<IEnumerable<CategoryDto>>(response.Categories);
خطای زیر را میگیرم
Mapping types:
RepeatedField`1 -> IEnumerable`1
Google.Protobuf.Collections.RepeatedField`1[[ProductCatalogService.GrpcService.Protos.GetAllResponse, ProductCatalogService.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.IEnumerable`1[[ProductCatalogService.Application.DTOs.CategoryDto, ProductCatalogService.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
لطفا راهنمایی بفرمایید