absolutealgorithm.api.common
Advanced tools
Sorry, the diff of this file is not supported yet
@@ -7,4 +7,3 @@ <?xml version="1.0" encoding="utf-8"?> | ||
| <Default Extension="json" ContentType="application/octet" /> | ||
| <Default Extension="md" ContentType="application/octet" /> | ||
| <Default Extension="nuspec" ContentType="application/octet" /> | ||
| </Types> |
@@ -5,7 +5,7 @@ <?xml version="1.0" encoding="utf-8"?> | ||
| <id>AbsoluteAlgorithm.Api.Common</id> | ||
| <version>1.0.0-dev.11</version> | ||
| <version>1.0.0-dev.10</version> | ||
| <authors>S Lalith Prasad</authors> | ||
| <description>Core foundational library for .NET distributed systems.</description> | ||
| <tags>c# asp.net dotnet mssql postgresql ratelimit distributed-systems response-caching logging resiliency healthchecks swagger openapi-documentation</tags> | ||
| <repository type="git" commit="779816a1def998ae856f6635bcec475cdb6b4855" /> | ||
| <repository type="git" commit="9a57d6951b3dd5c54f07d707abf8c951ec03c930" /> | ||
| <dependencies> | ||
@@ -12,0 +12,0 @@ <group targetFramework="net10.0"> |
-119
| # 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: | ||
| ```bash | ||
| dotnet add package AbsoluteAlgorithm.Api.Common --prerelease | ||
| ``` | ||
| ## Usage Setup | ||
| Configure the application in `Program.cs` using `ApplicationConfiguration` to set up databases, rate limiting, and the absolute pipeline. | ||
| ```csharp | ||
| 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) | ||
| } | ||
| } | ||
| }; | ||
| #endregion | ||
| 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 | ||
| | Property | Type | Description | | ||
| |----------|------|-------------| | ||
| | `UseRelationalDatabase` | `bool` | Enables relational database services and middleware. | | ||
| | `DatabasePolicies` | `List<DatabasePolicy>` | List of database configurations to initialize and manage. | | ||
| | `UseRateLimit` | `bool` | Enables rate limiting middleware. | | ||
| | `RateLimitPolicies` | `List<RateLimitPolicy>` | List of rate limiting policies to apply. | | ||
| ### DatabasePolicy | ||
| | Property | Type | Description | | ||
| |----------|------|-------------| | ||
| | `DatabaseProvider` | `DatabaseProvider` | The database type (e.g., `MSSQL`, `PostgreSQL`). | | ||
| | `ConnectionStringName` | `string` | **Environment variable name** containing the connection string. | | ||
| | `InitializeDatabase` | `bool` | If true, attempts to create the database if it doesn't exist. | | ||
| | `InitializeAuditTable` | `bool` | If true, sets up the `audit_logs` table and triggers. | | ||
| | `InitializationScript` | `string` | Custom SQL script executed during initialization (e.g., table creation). | | ||
| | `DatabaseName` | `string` | Unique name for the database connection (used for pooling/resources). | | ||
| | `MaxPoolSize` | `int` | Maximum size of the connection pool. | | ||
| | `MinPoolSize` | `int` | Minimum size of the connection pool. | | ||
| | `CommandTimeoutSeconds` | `int` | Time in seconds before a command times out. | | ||
| ### RateLimitPolicy | ||
| | Property | Type | Description | | ||
| |----------|------|-------------| | ||
| | `PolicyName` | `string` | Unique identifier for the policy (used in `[EnableRateLimiting]`). | | ||
| | `Algorithm` | `RateLimitAlgorithm` | The rate limiting algorithm (e.g., `FixedWindow`). | | ||
| | `Scope` | `RateLimitScope` | Scope of the limit (e.g., `IpAddress`, `User`). | | ||
| | `PermitLimit` | `int` | Number of permitted requests in the window. | | ||
| | `Window` | `TimeSpan` | Time window duration for the limit. | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet