Beispiel #1
0
        public static IApplicationBuilder UseRpcService <T>(this IApplicationBuilder builder, Action <RpcServiceOptions <T> > configureOptions) where T : class
        {
            var options = new RpcServiceOptions <T>();

            configureOptions?.Invoke(options);
            return(builder.UseMiddleware <RpcMiddleware <T> >(options));
        }
Beispiel #2
0
        public RouteManager(RpcServiceOptions <T> options)
        {
            _interfaceType    = typeof(T);
            _interfaceMethods = GetAllMethods(_interfaceType);
            _routeHandlers    = new Dictionary <string, Func <string, T, HttpContext, Task <RouteResponse> > >();
            _options          = options ?? throw new ArgumentNullException(nameof(options));

            foreach (var method in _interfaceMethods)
            {
                AddHandler(method.Name, MethodHandler);
            }
        }
Beispiel #3
0
        public RpcMiddleware(RequestDelegate next, RpcServiceOptions <T> options)
        {
            _next    = next;
            _options = options ?? new RpcServiceOptions <T>();

            if (_routeManagers.Values.Any(x => string.Equals(x.Item1.Prefix, options.Prefix, StringComparison.OrdinalIgnoreCase)))
            {
                throw new ApplicationException($"There is already an RPC service which handles requests with the prefix \"{options.Prefix ?? "null"}\"");
            }

            var instanceType = typeof(T);

            if (!_routeManagers.ContainsKey(instanceType))
            {
                _routeManagers.Add(instanceType, new Tuple <RpcServiceOptions <T>, object>(options, new RouteManager <T>(options)));
            }

            var tuple = _routeManagers[instanceType];

            _routeManager = (RouteManager <T>)tuple.Item2;
        }
Beispiel #4
0
 public static IApplicationBuilder UseRpcService <T>(this IApplicationBuilder builder, RpcServiceOptions <T> options) where T : class
 {
     return(builder.UseMiddleware <RpcMiddleware <T> >(options));
 }