public static BlueprintApiBuilder AddHateoasLinks(this BlueprintApiBuilder apiBuilder) { // Resource events needs authoriser services to be registered BuiltinBlueprintMiddlewares.TryAddAuthorisationServices(apiBuilder.Services); apiBuilder.Services.TryAddScoped <IResourceLinkGenerator, EntityOperationResourceLinkGenerator>(); apiBuilder.Pipeline(p => p.AddMiddleware <LinkGeneratorMiddlewareBuilder>(MiddlewareStage.PostExecution)); return(apiBuilder); }
/// <summary> /// Adds a Tasks 'server', <see cref="TaskExecutor" /> implementations in /// addition to provider-specific functionality that enables the execution of <see cref="IBackgroundTask" />s in /// this application. /// </summary> /// <remarks> /// Note that by default we DO NOT register recurring task support. /// </remarks> /// <param name="builder">The builder to add the task server to.</param> /// <param name="configureTasks">A builder callback to configure the provider implementation for tasks.</param> /// <returns>A <see cref="BlueprintApiBuilder" /> for configuration.</returns> /// <seealso cref="AddTasksClient" /> /// <seealso cref="BlueprintTasksServerBuilder.AddRecurringTasks" /> public static BlueprintApiBuilder AddBackgroundTasks( this BlueprintApiBuilder apiBuilder, Action <BlueprintTasksServerBuilder> configureTasks) { RegisterClient(apiBuilder); apiBuilder.Operations(o => o.AddConvention(new TasksOperationScannerConvention())); apiBuilder.Services.AddScoped <TaskExecutor>(); configureTasks(new BlueprintTasksServerBuilder(apiBuilder.Services)); return(apiBuilder); }
/// <summary> /// Adds an OpenAPI query that will return an OpenAPI specification at /openapi. /// </summary> /// <param name="pipelineBuilder">The pipeline builder to configure.</param> /// <param name="configure">An action to configure the <see cref="OpenApiOptions"/>.</param> /// <returns>This <see cref="BlueprintApiBuilder" /> for further configuration.</returns> public static BlueprintApiBuilder AddOpenApi(this BlueprintApiBuilder pipelineBuilder, Action <OpenApiOptions> configure) { pipelineBuilder.Services.AddOptions <OpenApiOptions>().Configure(o => { o.AddSchemaProcessor <BlueprintLinkSchemaProcessor>(); configure(o); }); pipelineBuilder.Services.AddSingleton(s => ActivatorUtilities.CreateInstance <OpenApiDocumentBuilder>(s).Build()); pipelineBuilder.Operations(o => o.AddOperation <OpenApiQuery>("AddOpenApi")); return(pipelineBuilder); }
public static IServiceCollection AddBlueprintApi( this IServiceCollection services, Action <BlueprintApiBuilder> configureApi) { Guard.NotNull(nameof(configureApi), configureApi); EnsureNotAlreadySetup(services, typeof(IApiOperationExecutor)); var apiBuilder = new BlueprintApiBuilder(services); configureApi(apiBuilder); apiBuilder.Build(); return(services); }
/// <summary> /// Adds an OpenAPI query that will return an OpenAPI specification at /openapi. /// </summary> /// <param name="pipelineBuilder">The pipeline builder to configure.</param> /// <returns>This <see cref="BlueprintApiBuilder" /> for further configuration.</returns> public static BlueprintApiBuilder AddOpenApi(this BlueprintApiBuilder pipelineBuilder) { pipelineBuilder.Services.AddOptions <OpenApiOptions>().Configure(o => { o.PostConfigure = d => { d.Info = new OpenApiInfo { Title = "Auto-generated API specification", }; }; o.AddSchemaProcessor <BlueprintLinkSchemaProcessor>(); }); pipelineBuilder.Services.AddSingleton(s => ActivatorUtilities.CreateInstance <OpenApiDocumentBuilder>(s).Build()); pipelineBuilder.Operations(o => o.AddOperation <OpenApiQuery>("AddOpenApi")); return(pipelineBuilder); }
/// <summary> /// Adds Elastic APM integration to this API, registering an <see cref="IApmTool" /> to allow /// tracking dependencies using Elastic APM. /// </summary> /// <param name="pipelineBuilder">The pipeline builder to configure.</param> /// <returns>This builder for further configuration.</returns> public static BlueprintApiBuilder AddElasticApm(this BlueprintApiBuilder pipelineBuilder) { pipelineBuilder.Services.AddSingleton <IApmTool, ElasticApmTool>(); return(pipelineBuilder); }
/// <summary> /// Registers HTTP-specific functionality and handling to this API instance. /// </summary> /// <param name="apiBuilder">The builder to register with.</param> /// <param name="configure">An optional action that can configure <see cref="BlueprintHttpBuilder" />, executed /// <c>after</c> the default configuration has been run.</param> /// <returns>This builder.</returns> public static BlueprintApiBuilder Http( this BlueprintApiBuilder apiBuilder, Action <BlueprintHttpBuilder> configure = null) { apiBuilder.Services.AddSingleton <IHttpRequestStreamReaderFactory, MemoryPoolHttpRequestStreamReaderFactory>(); apiBuilder.Services.AddSingleton <IHttpResponseStreamWriterFactory, MemoryPoolHttpResponseStreamWriterFactory>(); apiBuilder.Services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); apiBuilder.Services.AddOptions <BlueprintHttpOptions>(); apiBuilder.Services.AddOptions <BlueprintJsonOptions>(); apiBuilder.Services.Add(ServiceDescriptor.Transient <IConfigureOptions <BlueprintHttpOptions>, BlueprintHttpOptionsSetup>()); apiBuilder.Services.AddSingleton <IOutputFormatterSelector, DefaultOutputFormatterSelector>(); apiBuilder.Services.AddScoped <IApiLinkGenerator, ApiLinkGenerator>(); apiBuilder.AddMessageSource <HttpRouteMessagePopulationSource>(); apiBuilder.AddMessageSource <HttpBodyMessagePopulationSource>(); // "Owned" HTTP part sources apiBuilder.AddMessageSource( HttpPartMessagePopulationSource.Owned <FromCookieAttribute>( c => c.GetProperty("Request").GetProperty(nameof(HttpRequest.Cookies)), false)); apiBuilder.AddMessageSource( HttpPartMessagePopulationSource.Owned <FromHeaderAttribute>( c => c.GetProperty("Request").GetProperty(nameof(HttpRequest.Headers)), true)); apiBuilder.AddMessageSource( HttpPartMessagePopulationSource.Owned <FromQueryAttribute>( c => c.GetProperty("Request").GetProperty(nameof(HttpRequest.Query)), true)); // Catch-all query string population source apiBuilder.AddMessageSource( HttpPartMessagePopulationSource.CatchAll( "fromQuery", c => c.GetProperty("Request").GetProperty(nameof(HttpRequest.Query)), c => c.Descriptor.GetFeatureData <HttpOperationFeatureData>().HttpMethod == "GET", true)); apiBuilder.Services.AddSingleton <IOperationResultExecutor <ValidationFailedOperationResult>, ValidationFailedOperationResultExecutor>(); apiBuilder.Services.AddSingleton <IOperationResultExecutor <UnhandledExceptionOperationResult>, UnhandledExceptionOperationResultExecutor>(); apiBuilder.Services.AddSingleton <IOperationResultExecutor <OkResult>, OkResultOperationExecutor>(); apiBuilder.Services.AddSingleton <OkResultOperationExecutor>(); apiBuilder.Services.AddSingleton <IContextMetadataProvider, HttpContextMetadataProvider>(); apiBuilder.Operations(o => o .AddOperation <RootMetadataOperation>("AddHttp") .AddConvention(new HttpOperationScannerConvention())); apiBuilder.Compilation(c => c.AddVariableSource(new HttpVariableSource())); configure?.Invoke(new BlueprintHttpBuilder(apiBuilder.Services)); return(apiBuilder); }
/// <summary> /// Adds DataDog integration to this API, registering an <see cref="IApmTool" /> to allow /// tracking dependencies, and middleware that will manage spans. /// </summary> /// <param name="pipelineBuilder">The pipeline builder to configure.</param> /// <returns>This builder for further configuration.</returns> public static BlueprintApiBuilder AddDataDog(this BlueprintApiBuilder pipelineBuilder) { pipelineBuilder.Services.AddSingleton <IApmTool, DataDogApmTool>(); return(pipelineBuilder); }
/// <summary> /// Adds OpenTracing integration to this API, registering an <see cref="IApmTool" /> to allow /// tracking dependencies using the OpenTracing library. /// </summary> /// <param name="pipelineBuilder">The pipeline builder to configure.</param> /// <returns>This builder for further configuration.</returns> public static BlueprintApiBuilder AddOpenTracing(this BlueprintApiBuilder pipelineBuilder) { pipelineBuilder.Services.AddSingleton <IApmTool, OpenTracingApmTool>(); return(pipelineBuilder); }