Beispiel #1
0
        public GrpcCqrsClient(GrpcCqrsClientConfiguration configuration,
                              ILogger <GrpcCqrsClient> logger,
                              IGrpcClientAspect clientAspect = null)
        {
            _configuration = configuration;
            _logger        = logger;
            _clientAspect  = clientAspect;

            // client id definition
            Id = !string.IsNullOrWhiteSpace(_configuration.ClientId) ? _configuration.ClientId : Assembly.GetEntryAssembly().FullName.Split(',')[0];

            // resolve cqrs from assemblies
            var cqrs = configuration.ContractsAssemblies.SelectMany(CqrsInfoResolverUtil.GetCqrsDefinitions).ToList();

            _cqrsAdapter = new CqrsContractsAdapter(cqrs, configuration.ServiceNamePrefix);

            // create grpc invokation methods
            _grpcMethods = _cqrsAdapter.ToCqrsChannelInfo().ToDictionary(
                x => x.ChReqType,
                x => CreateGrpcMethodForCqrsChannel(x));

            // create mapper
            _mapper = _cqrsAdapter.CreateMapper();

            // create client
            var ch = new Channel(configuration.Url, configuration.Port, ChannelCredentials.Insecure);

            _invoker = new DefaultCallInvoker(ch);
        }
Beispiel #2
0
        public static GrpcCqrsClientConfiguration ToConfiguration(this GrpcCqrsClientRawConfiguration raw)
        {
            var cfg = new GrpcCqrsClientConfiguration
            {
                Url = raw.Url,
                HandleExceptions    = raw.HandleExceptions,
                Port                = raw.Port,
                TimeoutMs           = raw.TimeoutMs,
                ServiceNamePrefix   = raw.ServiceNamePrefix,
                ContractsAssemblies = raw.ContractsAssemblies.ToAssemblies(),
                ClientId            = raw.ClientId
            };

            return(cfg);
        }