public IDisposable Add(IJsonRpcHandler handler, JsonRpcHandlerOptions options)
        {
            var result = _parent.Add(handler, options);

            _compositeDisposable.Add(result);
            return(result);
        }
Esempio n. 2
0
        public static void Populate(this IJsonRpcHandlerCollection collection, IResolverContext resolverContext, IHandlersManager handlersManager)
        {
            var links = new List <JsonRpcHandlerLinkDescription>();

            foreach (var item in collection)
            {
                switch (item)
                {
                case JsonRpcHandlerFactoryDescription {
                        Method: { Length : > 0 }
                } factory :
                    handlersManager.Add(factory.Method, factory.HandlerFactory(resolverContext), factory.Options);
                    continue;

                case JsonRpcHandlerFactoryDescription factory:
                    handlersManager.Add(factory.HandlerFactory(resolverContext), factory.Options);
                    continue;

                case JsonRpcHandlerTypeDescription {
                        Method: { Length : > 0 }
                } type :
                    handlersManager.Add(type.Method, (resolverContext.Resolve(type.HandlerType) as IJsonRpcHandler) !, type.Options);
                    continue;

                case JsonRpcHandlerTypeDescription type:
                    handlersManager.Add((resolverContext.Resolve(type.HandlerType) as IJsonRpcHandler) !, type.Options);
                    continue;

                case JsonRpcHandlerInstanceDescription {
                        Method: { Length : > 0 }
                } instance :
                    handlersManager.Add(instance.Method, instance.HandlerInstance, instance.Options);
                    continue;

                case JsonRpcHandlerInstanceDescription instance:
                    handlersManager.Add(instance.HandlerInstance, instance.Options);
                    continue;

                case JsonRpcHandlerLinkDescription link:
                    links.Add(link);
                    continue;
                }
            }

            foreach (var link in links)
            {
                handlersManager.AddLink(link.Method, link.LinkToMethod);
            }
        }
Esempio n. 3
0
        public static void Populate(this IJsonRpcHandlerCollection collection, IServiceProvider serviceProvider, IHandlersManager handlersManager)
        {
            var links = new List <JsonRpcHandlerLinkDescription>();

            foreach (var item in collection)
            {
                switch (item)
                {
                case JsonRpcHandlerFactoryDescription factory when string.IsNullOrWhiteSpace(factory.Method):
                    handlersManager.Add(factory.HandlerFactory(serviceProvider), factory.Options);

                    continue;

                case JsonRpcHandlerFactoryDescription factory:
                    handlersManager.Add(factory.Method, factory.HandlerFactory(serviceProvider), factory.Options);
                    continue;

                case JsonRpcHandlerTypeDescription type when string.IsNullOrWhiteSpace(type.Method):
                    handlersManager.Add(ActivatorUtilities.CreateInstance(serviceProvider, type.HandlerType) as IJsonRpcHandler, type.Options);

                    continue;

                case JsonRpcHandlerTypeDescription type:
                    handlersManager.Add(type.Method, ActivatorUtilities.CreateInstance(serviceProvider, type.HandlerType) as IJsonRpcHandler, type.Options);
                    continue;

                case JsonRpcHandlerInstanceDescription instance when string.IsNullOrWhiteSpace(instance.Method):
                    handlersManager.Add(instance.HandlerInstance, instance.Options);

                    continue;

                case JsonRpcHandlerInstanceDescription instance:
                    handlersManager.Add(instance.Method, instance.HandlerInstance, instance.Options);
                    continue;

                case JsonRpcHandlerLinkDescription link:
                    links.Add(link);
                    continue;
                }
            }

            foreach (var link in links)
            {
                handlersManager.AddLink(link.Method, link.LinkToMethod);
            }
        }
Esempio n. 4
0
 public sealed override T AddHandler(string method, IJsonRpcHandler handler, JsonRpcHandlerOptions options)
 {
     _handlersManager.Add(method, handler, options);
     return((T)(object)this);
 }