Example #1
0
        public EventStoreGrpcClient(Uri address, Func <HttpClient> createHttpClient = default)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            _channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions {
                HttpClient = createHttpClient?.Invoke(),
            });
            var callInvoker = _channel.CreateCallInvoker().Intercept(new TypedExceptionInterceptor());

            _client = new Streams.Streams.StreamsClient(callInvoker);
            PersistentSubscriptions = new EventStorePersistentSubscriptionsGrpcClient(callInvoker);
            ProjectionsManager      = new EventStoreProjectionManagerGrpcClient(callInvoker);
            UsersManager            = new EventStoreUserManagerGrpcClient(callInvoker);
        }
        public EventStoreGrpcClient(EventStoreGrpcClientSettings settings = null)
        {
            settings ??= new EventStoreGrpcClientSettings(new UriBuilder {
                Scheme = Uri.UriSchemeHttps,
                Port   = 2113
            }.Uri);
            _channel = GrpcChannel.ForAddress(settings.Address, new GrpcChannelOptions {
                HttpClient = settings.CreateHttpClient?.Invoke()
            });
            var connectionName = settings.ConnectionName ?? $"ES-{Guid.NewGuid()}";

            var callInvoker = settings.Interceptors.Aggregate(
                _channel.CreateCallInvoker()
                .Intercept(new TypedExceptionInterceptor())
                .Intercept(new ConnectionNameInterceptor(connectionName)),
                (invoker, interceptor) => invoker.Intercept(interceptor));

            _client = new Streams.Streams.StreamsClient(callInvoker);
            PersistentSubscriptions = new EventStorePersistentSubscriptionsGrpcClient(callInvoker);
            ProjectionsManager      = new EventStoreProjectionManagerGrpcClient(callInvoker);
            UsersManager            = new EventStoreUserManagerGrpcClient(callInvoker);
        }