internal static IContainer AddDebugAdapterProtocolInternals <T>(this IContainer container, DebugAdapterRpcOptionsBase <T> options) where T : IJsonRpcHandlerRegistry <T>
        {
            if (options.Serializer == null)
            {
                throw new ArgumentException("Serializer is missing!", nameof(options));
            }

            container = container.AddJsonRpcServerCore(options);
            container.RegisterInstanceMany(new HandlerTypeDescriptorProvider(options.Assemblies), nonPublicServiceTypes: true);

            container.RegisterInstanceMany(options.Serializer);
            container.RegisterInstance(options.RequestProcessIdentifier);
            container.RegisterMany <DebugAdapterSettingsBag>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);
            container.RegisterMany <DapReceiver>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);
            container.RegisterMany <DebugAdapterRequestRouter>(Reuse.Singleton);
            container.RegisterMany <DebugAdapterHandlerCollection>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);
            container.RegisterInitializer <DebugAdapterHandlerCollection>(
                (manager, context) => {
                var descriptions = context.Resolve <IJsonRpcHandlerCollection>();
                descriptions.Populate(context, manager);
            }
                );
            container.RegisterMany <DapResponseRouter>(Reuse.Singleton);

            return(container);
        }
Example #2
0
        internal static IContainer AddLanguageProtocolInternals <T>(this IContainer container, LanguageProtocolRpcOptionsBase <T> options) where T : IJsonRpcHandlerRegistry <T>
        {
            options.RequestProcessIdentifier ??= options.SupportsContentModified
                ? new RequestProcessIdentifier(RequestProcessType.Parallel)
                : new RequestProcessIdentifier();

            if (options.Serializer == null)
            {
                throw new ArgumentException("Serializer is missing!", nameof(options));
            }

            container = container.AddJsonRpcServerCore(options);

            container.RegisterInstanceMany(options.Serializer);
            container.RegisterInstance(options.RequestProcessIdentifier);
            container.RegisterMany <LanguageProtocolSettingsBag>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);

            container.RegisterMany <SupportedCapabilities>(Reuse.Singleton);
            container.Register <TextDocumentIdentifiers>(Reuse.Singleton);
            container.RegisterInitializer <TextDocumentIdentifiers>((identifiers, context) => { identifiers.Add(context.GetServices <ITextDocumentIdentifier>().ToArray()); });
            container.RegisterMany <LspRequestRouter>(Reuse.Singleton);
            container.RegisterMany <SharedHandlerCollection>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);
            container.RegisterInitializer <SharedHandlerCollection>(
                (manager, context) => {
                var descriptions = context.Resolve <IJsonRpcHandlerCollection>();
                descriptions.Populate(context, manager);
            }
                );
            container.RegisterMany <ResponseRouter>(Reuse.Singleton);
            container.RegisterMany <ProgressManager>(Reuse.Singleton);

            return(container);
        }
Example #3
0
        internal static IContainer AddLanguageProtocolInternals <T>(this IContainer container, LanguageProtocolRpcOptionsBase <T> options) where T : IJsonRpcHandlerRegistry <T>
        {
            options.RequestProcessIdentifier ??= options.SupportsContentModified
                ? new RequestProcessIdentifier(RequestProcessType.Parallel)
                : new RequestProcessIdentifier();

            if (options.Serializer == null)
            {
                throw new ArgumentException("Serializer is missing!", nameof(options));
            }

            options.Services.AddLogging(builder => options.LoggingBuilderAction?.Invoke(builder));

            container = container.AddJsonRpcServerCore(options);
            container.RegisterInstanceMany(new LspHandlerTypeDescriptorProvider(options.Assemblies, options.UseAssemblyAttributeScanning), nonPublicServiceTypes: true);

            container.RegisterInstanceMany(options.Serializer);
            container.RegisterInstance(options.RequestProcessIdentifier);
            container.RegisterMany <LanguageProtocolSettingsBag>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);

            container.RegisterMany <SupportedCapabilities>(Reuse.Singleton);
            container.RegisterMany <OutputHandlerInitialized>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);
            container.Register <TextDocumentIdentifiers>(Reuse.Singleton);
            container.RegisterInitializer <TextDocumentIdentifiers>((identifiers, context) => { identifiers.Add(context.GetServices <ITextDocumentIdentifier>().ToArray()); });
            container.RegisterMany <LspRequestRouter>(Reuse.Singleton);
            container.RegisterMany <SharedHandlerCollection>(nonPublicServiceTypes: true, reuse: Reuse.Singleton);
            container.RegisterInitializer <SharedHandlerCollection>(
                (manager, context) => {
                var descriptions = context.Resolve <IJsonRpcHandlerCollection>();
                descriptions.Populate(context, manager);
            }
                );
            container.RegisterMany <ResponseRouter>(Reuse.Singleton);
            container.RegisterMany <ProgressManager>(Reuse.Singleton);

            if (options.UseAssemblyAttributeScanning)
            {
                container.RegisterMany(
                    options.Assemblies
                    .SelectMany(z => z.GetCustomAttributes <AssemblyRegistrationOptionsAttribute>())
                    .SelectMany(z => z.Types)
                    .SelectMany(z => z.GetCustomAttributes <RegistrationOptionsConverterAttribute>())
                    .Select(z => z.ConverterType)
                    .Where(z => typeof(IRegistrationOptionsConverter).IsAssignableFrom(z)),
                    reuse: Reuse.Singleton
                    );
            }
            else
            {
                container.RegisterMany(
                    options.Assemblies
                    .SelectMany(z => z.GetTypes())
                    .Where(z => z.IsClass && !z.IsAbstract)
                    .Where(z => typeof(IRegistrationOptionsConverter).IsAssignableFrom(z)),
                    reuse: Reuse.Singleton
                    );
            }

            return(container);
        }
        internal static IContainer AddJsonRpcServerInternals(this IContainer container, JsonRpcServerOptions options)
        {
            if (options.Serializer == null)
            {
                throw new ArgumentException("Serializer is missing!", nameof(options));
            }

            if (options.RequestProcessIdentifier == null)
            {
                throw new ArgumentException("RequestProcessIdentifier is missing!", nameof(options));
            }

            container = container.AddJsonRpcServerCore(options);
            container.RegisterInstanceMany(new HandlerTypeDescriptorProvider(options.Assemblies), nonPublicServiceTypes: true);

            container.RegisterInstance(options.Serializer);
            if (options.Receiver == null)
            {
                container.Register <IReceiver, Receiver>(Reuse.Singleton);
            }
            else
            {
                container.RegisterInstance(options.Receiver);
            }
            container.RegisterMany <AlwaysOutputFilter>(Reuse.Singleton, nonPublicServiceTypes: true);

            container.RegisterInstance(options.RequestProcessIdentifier);
            container.RegisterInstance(options.OnUnhandledException ?? (e => { }));

            container.RegisterMany <RequestRouter>(Reuse.Singleton);
            container.RegisterMany <HandlerCollection>(
                nonPublicServiceTypes: true,
                serviceTypeCondition: type => typeof(IHandlersManager) == type || type == typeof(HandlerCollection),
                reuse: Reuse.Singleton
                );
            container.RegisterInitializer <IHandlersManager>(
                (manager, context) => {
                var descriptions = context.Resolve <IJsonRpcHandlerCollection>();
                descriptions.Populate(context, manager);
            }
                );

            container.Register <IJsonRpcServerFacade, DefaultJsonRpcServerFacade>(reuse: Reuse.Singleton);
            container.RegisterInstance <IOptionsFactory <JsonRpcServerOptions> >(new ValueOptionsFactory <JsonRpcServerOptions>(options));
            container.RegisterMany <JsonRpcServer>(
                serviceTypeCondition: type => type == typeof(IJsonRpcServer) || type == typeof(JsonRpcServer),
                reuse: Reuse.Singleton,
                setup: Setup.With(condition: req => req.IsResolutionRoot || req.Container.Resolve <IInsanceHasStarted>().Started)
                );

            return(container);
        }
Example #5
0
        internal static IContainer AddJsonRpcServerInternals(this IContainer container, JsonRpcServerOptions options)
        {
            if (options.Serializer == null)
            {
                throw new ArgumentException("Serializer is missing!", nameof(options));
            }

            if (options.Receiver == null)
            {
                throw new ArgumentException("Receiver is missing!", nameof(options));
            }

            if (options.RequestProcessIdentifier == null)
            {
                throw new ArgumentException("RequestProcessIdentifier is missing!", nameof(options));
            }

            container = container.AddJsonRpcServerCore(options);

            container.RegisterInstance(options.Serializer ?? new JsonRpcSerializer());
            container.RegisterInstance(options.Receiver);
            container.RegisterInstance(options.RequestProcessIdentifier);
            container.RegisterInstance(options.OnUnhandledException ?? (e => { }));

            container.RegisterMany <RequestRouter>(Reuse.Singleton);
            container.RegisterMany <HandlerCollection>(
                nonPublicServiceTypes: true,
                serviceTypeCondition: type => typeof(IHandlersManager) == type || type == typeof(HandlerCollection),
                reuse: Reuse.Singleton
                );
            container.RegisterInitializer <IHandlersManager>(
                (manager, context) => {
                var descriptions = context.Resolve <IJsonRpcHandlerCollection>();
                descriptions.Populate(context, manager);
            }
                );

            container.RegisterInstance <IOptionsFactory <JsonRpcServerOptions> >(new ValueOptionsFactory <JsonRpcServerOptions>(options));
            container.RegisterMany <JsonRpcServer>(serviceTypeCondition: type => type == typeof(IJsonRpcServer) || type == typeof(JsonRpcServer), reuse: Reuse.Singleton);

            return(container);
        }