public WebSocketsProxyMiddleware(RequestDelegate next, ServiceRouteCache serviceRouteCache, IOptions <RpcOptions> rpcOptions) { _next = next; _serviceRouteCache = serviceRouteCache; _rpcOptions = rpcOptions.Value; }
public RpcRequestRunner(ISender sender, RpcOptions options) { RpcRequestRunnerValidator.ValidateSender(sender); RpcRequestRunnerValidator.ValidateOptions(options); this.sender = sender; this.requestTypeProvider = new DictionarySearchRequestTypeProvider(options.Requests, options.MatchingConvention); }
/// <summary> /// Our requests and requests handlers are nested together in one static class. /// It's the static class' name we want to use when routing. /// </summary> public static RpcOptions UseAppsCustomNameMapping(this RpcOptions options) { options.MatchingConvention = requestType => { return(requestType.DeclaringType.Name.ToLowerInvariant()); }; return(options); }
protected MessageReceivedHandlerBase( IParameterParser parameterParser, ISerializer serializer, IOptions <RpcOptions> rpcOptions, IServiceExecutor serviceExecutor) { _parameterParser = parameterParser; _serializer = serializer; _serviceExecutor = serviceExecutor; _rpcOptions = rpcOptions.Value; }
/// <summary> /// Adds services for the MediatR RPC behavior, to enable sending <see cref="IRequest{TResponse}"/> given a corresponding name and payload. /// </summary> /// <param name="services">Service collection to register to.</param> /// <param name="configuration">The configurator for the necessary options.</param> /// <returns>The same service collection.</returns> public static IServiceCollection AddMediatrRpc(this IServiceCollection services, Action <RpcOptions> configuration) { Validate(services, configuration); var options = new RpcOptions(); configuration.Invoke(options); services.AddSingleton(options); services.AddSingleton <RpcRequestRunner>(); services.AddSingleton <IRpcRequestRunner>(provider => provider.GetService <RpcRequestRunner>()); return(services); }
internal static void ValidateOptions(RpcOptions options) { AssertHelper.ValidateIsNotNull(options.Requests, nameof(options.Requests)); AssertHelper.ValidateIsNotNull(options.MatchingConvention, nameof(options.MatchingConvention)); var nonMediatrRequests = options.Requests .Where(t => false == RequestTypeScanner.IsMediatrRequest(t)) .ToList(); if (nonMediatrRequests.Any()) { var nonMediatrRequestTypeNames = nonMediatrRequests .Aggregate(new System.Text.StringBuilder(), (a, t) => a.AppendLine(t.FullName)); throw new ArgumentException($"All request types needs to derive from {nameof(IRequest)}. Non-accepted types: {nonMediatrRequestTypeNames}", nameof(options.Requests)); } }
public DotNettyTcpServerMessageListener(IOptions <RpcOptions> rpcOptions, IHostEnvironment hostEnvironment, ITransportMessageDecoder transportMessageDecoder, IHealthCheck healthCheck) { _hostEnvironment = hostEnvironment; _transportMessageDecoder = transportMessageDecoder; _healthCheck = healthCheck; _rpcOptions = rpcOptions.Value; _hostAddress = NetUtil.GetRpcAddressModel(); if (_rpcOptions.IsSsl) { Check.NotNullOrEmpty(_rpcOptions.SslCertificateName, nameof(_rpcOptions.SslCertificateName)); } Logger = NullLogger <DotNettyTcpServerMessageListener> .Instance; }
private static void AddRequestMethod(CodeWriter bodyWriter, RpcOptions options, string template) { switch (options.Method) { case "GET": bodyWriter.Append($"[HttpGet{template}]"); break; case "POST": bodyWriter.Append($"[HttpPost{template}]"); break; case "PUT": bodyWriter.Append($"[HttpPut{template}]"); break; case "DELETE": bodyWriter.Append($"[HttpDelete{template}]"); break; } }
protected ServiceRouteManagerBase(ServiceRouteCache serviceRouteCache, IServiceEntryManager serviceEntryManager, ILockerProvider lockerProvider, IOptions <RegistryCenterOptions> registryCenterOptions, IOptions <RpcOptions> rpcOptions) { _serviceRouteCache = serviceRouteCache; _serviceEntryManager = serviceEntryManager; _lockerProvider = lockerProvider; _registryCenterOptions = registryCenterOptions.Value; _rpcOptions = rpcOptions.Value; Check.NotNullOrEmpty(_registryCenterOptions.RoutePath, nameof(_registryCenterOptions.RoutePath)); Check.NotNullOrEmpty(_rpcOptions.Token, nameof(_rpcOptions.Token)); _serviceRouteCache.OnRemoveServiceRoutes += async descriptors => { if (_rpcOptions.RemoveUnhealthServer) { foreach (var descriptor in descriptors) { await RegisterRouteWithLockAsync(descriptor); } } }; }
/// <summary> /// Use the requests name when matching types. /// </summary> /// <param name="options">Options to set the convention for.</param> /// <returns>The updated options.</returns> public static RpcOptions UseExactRequestTypeNameMatchingConvention(this RpcOptions options) { options.MatchingConvention = d => d.Name; return(options); }
/// <summary> /// Scans for request types in the given collection of types. /// </summary> /// <param name="options">Options to register the found requests in.</param> /// <param name="types">A list for scanning request types.</param> /// <returns>The updated options.</returns> public static RpcOptions ScanRequests(this RpcOptions options, IEnumerable <Type> types) { options.Requests = RequestTypeScanner.FindRequestTypes(types).ToList(); return(options); }
/// <summary> /// Scans for request types in the given assemblies. /// </summary> /// <param name="options">Options to register the found requests in.</param> /// <param name="assemblies">Assemblies for scanning request types.</param> /// <returns>The updated options.</returns> public static RpcOptions ScanRequests(this RpcOptions options, params Assembly[] assemblies) { var definedTypes = assemblies.SelectMany(a => a.DefinedTypes); return(ScanRequests(options, definedTypes)); }
public RpcRunnerFixture() { this.senderFake = A.Fake <ISender>(); this.options = new RpcOptions() .UseExactRequestTypeNameMatchingConvention(); }
public RpcTokenValidator(IOptions <RpcOptions> rpcOptions, ICurrentRpcToken currentRpcToken) { _currentRpcToken = currentRpcToken; _rpcOptions = rpcOptions.Value; }