/flowable-sdk-dotnet

Flowable API SDK Client for .NET

Primary LanguageC#MIT LicenseMIT

flowable-sdk-dotnet

Build CodeQL NuGet contributionswelcome Conventional Commits License

GitHub Actions Build History

Flowable HTTP SDK Client for .NET

Registration in Dependency Injection (DI) container

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddFlowableHttpClients(
        this IServiceCollection services, IConfiguration configuration)
    {
        var httpClientOptions = configuration
            .GetSection(FlowableHttpClientOptions.FlowableClientSection)
            .Get<FlowableHttpClientOptions>();

        services.AddOptions<FlowableHttpClientOptions>().Bind(configuration);

        services.AddHttpClient<IFlowableProcessHttpClient, FlowableProcessHttpClient>(options =>
        {
            options.BaseAddress = new Uri(httpClientOptions.BaseUrlProcessApi);
        });

        services.AddHttpClient<IFlowableCaseHttpClient, FlowableCaseHttpClient>(options =>
        {
            options.BaseAddress = new Uri(httpClientOptions.BaseUrlCmmnApi);
        });
        return services;
    }

    public static IServiceCollection AddFlowableExternalWorkerHttpClient(
        this IServiceCollection services, IConfiguration configuration)
    {
        var httpClientOptions = configuration
            .GetSection(FlowableHttpClientOptions.FlowableClientSection)
            .Get<FlowableHttpClientOptions>();

        services.AddOptions<FlowableHttpClientOptions>().Bind(configuration);

        services.AddHttpClient<IFlowableExternalWorkerHttpClient, FlowableExternalWorkerHttpClient>(
            options =>
            {
                options.BaseAddress = new Uri(httpClientOptions.BaseUrlExternalWorker);
            }).AddPolicyHandler(GetCircuitBreakerPolicy());

        static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy() =>
            HttpPolicyExtensions
                .HandleTransientHttpError()
                .Or<HttpRequestException>()
                .CircuitBreakerAsync(5, TimeSpan.FromSeconds(60));

        return services;
    }
}

public class FlowableHttpClientOptions
{
    public const string FlowableClientSection = "FlowableHttpClientOptions";

    public string BaseUrlExternalWorker { get; set; }

    public string BaseUrlCmmnApi { get; set; }

    public string BaseUrlProcessApi { get; set; }
}