Beispiel #1
0
        /// <summary>
        /// Adds the ability for this graphql server to raise subscription events that can be published.
        /// </summary>
        /// <typeparam name="TSchema">The type of schema being configured.</typeparam>
        /// <param name="schemaBuilder">The schema builder.</param>
        /// <returns>GraphQL.AspNet.Interfaces.Configuration.ISchemaBuilder&lt;TSchema&gt;.</returns>
        public static ISchemaBuilder <TSchema> AddSubscriptionPublishing <TSchema>(
            this ISchemaBuilder <TSchema> schemaBuilder)
            where TSchema : class, ISchema
        {
            var extension = new SubscriptionPublisherSchemaExtension <TSchema>();

            // register the in-process publisher to the service collection before
            // if one is not already registered
            var defaultPublisher = CreateDefaultSubscriptionPublisherDescriptor();

            extension.OptionalServices.Add(defaultPublisher);

            // register the internal queueing mechanism that will asyncrounously transfer
            // raised events from controller methods to the registered subscription publisher
            schemaBuilder.AsServiceCollection().AddSingleton <SubscriptionEventQueue>();
            schemaBuilder.AsServiceCollection().AddHostedService <SubscriptionPublicationService>();
            schemaBuilder.AsServiceCollection().TryAdd(CreateDefaultSubscriptionRouterDescriptor());

            schemaBuilder.Options.RegisterExtension(extension);
            schemaBuilder.QueryExecutionPipeline.AddMiddleware <PublishRaisedSubscriptionEventsMiddleware <TSchema> >(
                ServiceLifetime.Singleton);

            return(schemaBuilder);
        }