Table of Contents

Class ApiServiceBuilder

Namespace
BytLabs.Api
Assembly
BytLabs.Api.dll

Builder class for configuring and constructing a web API application with standard middleware and services. Implements a fluent interface pattern for step-by-step configuration.

public class ApiServiceBuilder : ApiBuilderSteps.IInitialStep, ApiBuilderSteps.IMultiTenantStep, ApiBuilderSteps.IMetricsStep, ApiBuilderSteps.ITracingStep, ApiBuilderSteps.IHealthCheckStep, ApiBuilderSteps.ILoggingStep, ApiBuilderSteps.IAdditionalConfigurationStep, ApiBuilderSteps.IWebApplicationBuilder
Inheritance
ApiServiceBuilder
Implements
Inherited Members

Constructors

ApiServiceBuilder(WebApplicationBuilder)

Initializes a new instance of the ApiServiceBuilder class.

public ApiServiceBuilder(WebApplicationBuilder webApplicationBuilder)

Parameters

webApplicationBuilder WebApplicationBuilder

The ASP.NET Core web application builder.

Methods

BuildWebApp(Action<WebApplication>?)

Builds and configures the web application with standard middleware components. Sets up header propagation, request logging, health checks, and development-specific features.

public WebApplication BuildWebApp(Action<WebApplication>? appConfig = null)

Parameters

appConfig Action<WebApplication>

Optional action to configure additional middleware or application options.

Returns

WebApplication

A configured WebApplication instance ready to run.

CreateBuilder(WebApplicationBuilder)

Creates a new instance of the API service builder with the specified web application builder.

public static ApiBuilderSteps.IInitialStep CreateBuilder(WebApplicationBuilder webApplicationBuilder)

Parameters

webApplicationBuilder WebApplicationBuilder

The ASP.NET Core web application builder to use for configuration.

Returns

ApiBuilderSteps.IInitialStep

An initial configuration step to begin the builder chain.

WithHealthChecks(Action<IHealthChecksBuilder>?)

Configures health checks for monitoring the application's status and dependencies. Adds standard health check endpoints and custom health checks as specified.

public ApiBuilderSteps.IAdditionalConfigurationStep WithHealthChecks(Action<IHealthChecksBuilder>? healthCheckBuilder = null)

Parameters

healthCheckBuilder Action<IHealthChecksBuilder>

Optional action to configure additional health checks and endpoints.

Returns

ApiBuilderSteps.IAdditionalConfigurationStep

The next configuration step for additional service configuration.

WithHttpContextAccessor(Action<UserContextBuilder>?)

Configures HTTP context accessor and user context providers for the application. Enables header propagation and sets up user context resolution.

public ApiBuilderSteps.IMultiTenantStep WithHttpContextAccessor(Action<UserContextBuilder>? configureUserContext = null)

Parameters

configureUserContext Action<UserContextBuilder>

Optional action to configure additional user context settings.

Returns

ApiBuilderSteps.IMultiTenantStep

The next configuration step for multi-tenant setup.

WithLogging(Action<LoggerConfiguration>?)

Configures logging services using Serilog based on the application's configuration. Sets up log sinks, enrichers, and logging levels.

public ApiBuilderSteps.IMetricsStep WithLogging(Action<LoggerConfiguration>? loggerConfiguration = null)

Parameters

loggerConfiguration Action<LoggerConfiguration>

Optional action to configure additional logging options and sinks.

Returns

ApiBuilderSteps.IMetricsStep

The next configuration step for metrics setup.

WithMetrics(Action<MeterProviderBuilder>?)

Configures metrics collection and reporting using OpenTelemetry. Sets up meter providers and custom metrics based on the application's configuration.

public ApiBuilderSteps.ITracingStep WithMetrics(Action<MeterProviderBuilder>? configureMetrics = null)

Parameters

configureMetrics Action<MeterProviderBuilder>

Optional action to configure additional metrics options and custom meters.

Returns

ApiBuilderSteps.ITracingStep

The next configuration step for tracing setup.

WithMultiTenantContext(Action<MultitenancyBuilder>?)

Configures multi-tenant support for the application, enabling tenant resolution and context management.

public ApiBuilderSteps.ILoggingStep WithMultiTenantContext(Action<MultitenancyBuilder>? configureMultitenancy = null)

Parameters

configureMultitenancy Action<MultitenancyBuilder>

Optional action to configure additional multi-tenancy settings.

Returns

ApiBuilderSteps.ILoggingStep

The next configuration step for logging setup.

WithServiceConfiguration(Action<IServiceCollection>?)

Allows for additional service configuration and dependency injection setup. Use this method to register custom services or override existing ones.

public ApiBuilderSteps.IWebApplicationBuilder WithServiceConfiguration(Action<IServiceCollection>? serviceCollection = null)

Parameters

serviceCollection Action<IServiceCollection>

Optional action to configure additional services in the dependency injection container.

Returns

ApiBuilderSteps.IWebApplicationBuilder

The web application builder for final configuration.

WithTracing(Action<TracerProviderBuilder>?)

Configures distributed tracing using OpenTelemetry. Sets up trace providers and sampling based on the application's configuration.

public ApiBuilderSteps.IHealthCheckStep WithTracing(Action<TracerProviderBuilder>? configureTracing = null)

Parameters

configureTracing Action<TracerProviderBuilder>

Optional action to configure additional tracing options and custom spans.

Returns

ApiBuilderSteps.IHealthCheckStep

The next configuration step for health check setup.