internal JsonRpcServer(JsonRpcServerOptions options) : base(options) { var outputHandler = new OutputHandler( options.Output, options.Serializer, options.LoggerFactory.CreateLogger <OutputHandler>() ); var services = options.Services; services.AddLogging(); var receiver = options.Receiver; var serializer = options.Serializer; _disposable = options.CompositeDisposable; services.AddSingleton <IOutputHandler>(outputHandler); services.AddSingleton(serializer); services.AddSingleton(serializer); services.AddSingleton(options.RequestProcessIdentifier); services.AddSingleton(receiver); services.AddSingleton(options.LoggerFactory); services.AddJsonRpcMediatR(options.Assemblies); services.AddSingleton <IJsonRpcServer>(this); services.AddSingleton <IRequestRouter <IHandlerDescriptor>, RequestRouter>(); services.AddSingleton <IResponseRouter, ResponseRouter>(); _collection = new HandlerCollection(); services.AddSingleton(_collection); services.AddSingleton <IHandlersManager>(_ => _.GetRequiredService <HandlerCollection>()); EnsureAllHandlersAreRegistered(); var serviceProvider = services.BuildServiceProvider(); _disposable.Add(serviceProvider); _serviceProvider = serviceProvider; HandlersManager = _collection; var requestRouter = _serviceProvider.GetRequiredService <IRequestRouter <IHandlerDescriptor> >(); var router = ResponseRouter = _serviceProvider.GetRequiredService <IResponseRouter>(); _connection = new Connection( options.Input, outputHandler, options.Receiver, options.RequestProcessIdentifier, requestRouter, router, options.LoggerFactory, options.OnUnhandledException ?? (e => { }), options.CreateResponseException, options.MaximumRequestTimeout, options.SupportsContentModified, options.Concurrency ); _disposable.Add(_connection); _collection.Add(_serviceProvider.GetRequiredService <IEnumerable <IJsonRpcHandler> >().ToArray()); options.AddLinks(_collection); }
public RequestRouter(HandlerCollection collection, ISerializer serializer) { _collection = collection; _serializer = serializer; }
public RequestRouter(HandlerCollection collection, ISerializer serializer, IServiceScopeFactory serviceScopeFactory, ILoggerFactory loggerFactory) : base(serializer, serviceScopeFactory, loggerFactory.CreateLogger <RequestRouter>()) { _collection = collection; }
internal JsonRpcServer( Stream input, Stream output, IReciever reciever, IRequestProcessIdentifier requestProcessIdentifier, ILoggerFactory loggerFactory, ISerializer serializer, IServiceCollection services, IEnumerable <Assembly> assemblies) { var outputHandler = new OutputHandler(output, serializer); services.AddLogging(); _reciever = reciever; _serializer = serializer; _collection = new HandlerCollection(); services.AddSingleton <IOutputHandler>(outputHandler); services.AddSingleton(_collection); services.AddSingleton(_serializer); services.AddSingleton <OmniSharp.Extensions.JsonRpc.ISerializer>(_serializer); services.AddSingleton(requestProcessIdentifier); services.AddSingleton(_reciever); services.AddSingleton(loggerFactory); services.AddJsonRpcMediatR(assemblies); services.AddSingleton <IJsonRpcServer>(this); services.AddSingleton <IRequestRouter, RequestRouter>(); services.AddSingleton <IReciever, Reciever>(); services.AddSingleton <IResponseRouter, ResponseRouter>(); var foundHandlers = services .Where(x => typeof(IJsonRpcHandler).IsAssignableFrom(x.ServiceType) && x.ServiceType != typeof(IJsonRpcHandler)) .ToArray(); // Handlers are created at the start and maintained as a singleton foreach (var handler in foundHandlers) { services.Remove(handler); if (handler.ImplementationFactory != null) { services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationFactory)); } else if (handler.ImplementationInstance != null) { services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationInstance)); } else { services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationType)); } } _serviceProvider = services.BuildServiceProvider(); var handlers = _serviceProvider.GetServices <IJsonRpcHandler>().ToArray(); _collection.Add(handlers); _requestRouter = _serviceProvider.GetRequiredService <IRequestRouter>(); _responseRouter = _serviceProvider.GetRequiredService <IResponseRouter>(); _connection = ActivatorUtilities.CreateInstance <Connection>(_serviceProvider, input); }
public RequestRouter(HandlerCollection collection, ISerializer serializer, IServiceScopeFactory serviceScopeFactory) { _collection = collection; _serializer = serializer; _serviceScopeFactory = serviceScopeFactory; }
public RequestRouter(HandlerCollection collection) { _collection = collection; }