AbsoluteAlgorithm.Api.Common 1.0.0-dev.16

This is a prerelease version of AbsoluteAlgorithm.Api.Common.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package AbsoluteAlgorithm.Api.Common --version 1.0.0-dev.16
                    
NuGet\Install-Package AbsoluteAlgorithm.Api.Common -Version 1.0.0-dev.16
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AbsoluteAlgorithm.Api.Common" Version="1.0.0-dev.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AbsoluteAlgorithm.Api.Common" Version="1.0.0-dev.16" />
                    
Directory.Packages.props
<PackageReference Include="AbsoluteAlgorithm.Api.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AbsoluteAlgorithm.Api.Common --version 1.0.0-dev.16
                    
#r "nuget: AbsoluteAlgorithm.Api.Common, 1.0.0-dev.16"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AbsoluteAlgorithm.Api.Common@1.0.0-dev.16
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AbsoluteAlgorithm.Api.Common&version=1.0.0-dev.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AbsoluteAlgorithm.Api.Common&version=1.0.0-dev.16&prerelease
                    
Install as a Cake Tool

AbsoluteAlgorithm.Api.Common

A comprehensive common library for building robust ASP.NET Core Web APIs, featuring database management, audit logging, rate limiting, and standard middleware pipelines.

Installation

Install the package via NuGet:

dotnet add package AbsoluteAlgorithm.Api.Common --prerelease

Download from NuGet: https://www.nuget.org/packages/AbsoluteAlgorithm.Api.Common

Usage Setup

Configure the application in Program.cs using ApplicationConfiguration to set up databases, rate limiting, and the absolute pipeline.

try
{
    ApplicationConfiguration appConfig = new ApplicationConfiguration
    {
        UseRelationalDatabase = true,
        DatabasePolicies = new List<DatabasePolicy>
        {
            new DatabasePolicy
            {
                DatabaseProvider = DatabaseProvider.MSSQL,
                ConnectionStringName = "MSSQLCS",
                InitializeDatabase = true,
                InitializeAuditTable = true,
                InitializationScript = msSqlScript,
                DatabaseName = "testdb",
                MaxPoolSize = 100,
                MinPoolSize = 10,
                CommandTimeoutSeconds = 30
            },
            new DatabasePolicy
            {
                DatabaseProvider = DatabaseProvider.PostgreSQL,
                ConnectionStringName = "POSTGRESCS",
                InitializeDatabase = true,
                InitializeAuditTable = true,
                InitializationScript = postgreSqlScript,
                DatabaseName = "test_db",
                MaxPoolSize = 100,
                MinPoolSize = 10,
                CommandTimeoutSeconds = 30
            }
        },
        UseRateLimit = true,
        RateLimitPolicies = new List<RateLimitPolicy>
        {
            new RateLimitPolicy
            {
                PolicyName = "rpol",
                Algorithm = RateLimitAlgorithm.FixedWindow,
                Scope = RateLimitScope.IpAddress,
                PermitLimit = 2,
                Window = TimeSpan.FromSeconds(2)
            }
        }
    };

    WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
    builder.RegisterAbsoluteWebApplicationBuilder(appConfig);

    WebApplication app = builder.Build();

    app.UseAbsolutePipeline(appConfig);

    app.Run();
}
catch (Exception ex)
{
    var logger = LogManager.GetCurrentClassLogger();
    logger.Error(ex, "an error occured: {message}", ex.Message);
    throw;
}
finally
{
    LogManager.Shutdown();
}

Configuration Reference

ApplicationConfiguration

  • UseRelationalDatabase (bool): Enables relational database services and middleware.
  • DatabasePolicies (List<DatabasePolicy>): A list of database configurations to initialize and manage.
  • UseRateLimit (bool): Enables rate limiting middleware.
  • RateLimitPolicies (List<RateLimitPolicy>): A list of rate limiting policies to apply.

DatabasePolicy

  • DatabaseProvider (DatabaseProvider): Specifies the database type (e.g., MSSQL, PostgreSQL).
  • ConnectionStringName (string): The environment variable name that holds the connection string.
  • InitializeDatabase (bool): If true, the library will attempt to create the database if it does not already exist.
  • InitializeAuditTable (bool): If true, sets up the audit_logs table and corresponding triggers for automatic logging.
  • InitializationScript (string): A custom SQL script to be executed during the initialization phase, ideal for creating tables or seeding data.
  • DatabaseName (string): A unique name for the database connection, used for managing connection pooling and other resources.
  • MaxPoolSize (int): Defines the maximum number of connections allowed in the connection pool.
  • MinPoolSize (int): Defines the minimum number of connections to maintain in the connection pool.
  • CommandTimeoutSeconds (int): The time in seconds to wait for a database command to execute before it times out.

RateLimitPolicy

  • PolicyName (string): A unique identifier for the rate limiting policy, which can be referenced in the [EnableRateLimiting] attribute on controllers or endpoints.
  • Algorithm (RateLimitAlgorithm): The algorithm used for rate limiting (e.g., FixedWindow).
  • Scope (RateLimitScope): The scope at which the limit is applied (e.g., IpAddress, User).
  • PermitLimit (int): The number of requests permitted within the specified time window.
  • Window (TimeSpan): The duration of the time window for the rate limit.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated