diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 23c5f9c..dd49689 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,9 +25,8 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 3.1.x - 5.0.x 6.0.x + 7.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eb2e9f..dab6aee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,55 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [2.6.0] - 2024-08-22 +- βš™ IdempotentAPI.MinimalAPI `v3.2.0`: Add the option to configure special types in the `IIdempotencyOptionsProvider` to be excluded from the API actions (e.g., `[FromServices] DbContext context`). This will solve the self-referencing loop issue. For example, we can configure the `ExcludeRequestSpecialTypes` in the following way. Thank you, [@csimonsson](https://github.com/csimonsson), for reporting issue [#81](https://github.com/ikyriak/IdempotentAPI/issues/81) and help improving the code. + + ```c# + // Program.cs + // ... + builder.Services.AddIdempotentMinimalAPI(new IdempotencyOptionsProvider()); + // ... + ``` + ```c# + // IdempotencyOptionsProvider.cs + using IdempotentAPI.Core; + using IdempotentAPI.MinimalAPI; + using IdempotentAPI.TestWebMinimalAPIs.ApiContext; + using Microsoft.EntityFrameworkCore; + + namespace IdempotentAPI.TestWebMinimalAPIs + { + public class IdempotencyOptionsProvider : IIdempotencyOptionsProvider + { + private readonly List ExcludeRequestSpecialTypes = new() + { + typeof(DbContext), + }; + + public IIdempotencyOptions GetIdempotencyOptions(IHttpContextAccessor httpContextAccessor) + { + // WARNING: This example implementation shows we can provide different IdempotencyOptions per case. + //switch (httpContextAccessor?.HttpContext?.Request.Path) + //{ + // case "/v6/TestingIdempotentAPI/test": + // return new IdempotencyOptions() + // { + // ExpireHours = 1, + // ExcludeRequestSpecialTypes = ExcludeRequestSpecialTypes, + // }; + //} + + return new IdempotencyOptions() + { + ExcludeRequestSpecialTypes = ExcludeRequestSpecialTypes, + }; + } + } + } + ``` + + ## [2.5.0] - 2024-07-10 - 🌟 Support [FastEndpoints](https://fast-endpoints.com/), a developer-friendly alternative to Minimal APIs and MVC. Thank you, [@CaptainPowerTurtle](https://github.com/CaptainPowerTurtle), for reporting issue [#72](https://github.com/ikyriak/IdempotentAPI/issues/72) and [@dj-nitehawk](https://github.com/dj-nitehawk) for helping me integrate with `FastEndpoints` πŸ™πŸ’ͺ. - βš™ Add the option to configure the Newtonsoft `SerializerSettings` based on our needs. For example, this will enable us to use [NodaTime](https://nodatime.org/) in our DTOs. Thank you, [@angularsen](https://github.com/angularsen), for reporting the issue [#74](https://github.com/ikyriak/IdempotentAPI/issues/74) and sharing your ideas to improve the `IdempotentAPI` library πŸ™. diff --git a/README.md b/README.md index 317fe1b..7d20030 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Idempotent API (v2.5.0) +# Idempotent API (v2.6.0) @@ -123,7 +123,7 @@ The following figure shows a simplified example of the `IdempotentAPI` library f Let's see how we could use the NuGet packages in a Web API project. For more examples and code, you can check the [sample projects](https://github.com/ikyriak/IdempotentAPI/tree/master/samples). The `IdempotentAPI` can be installed via the NuGet UI or the NuGet package manager console: ```powershell -PM> Install-Package IdempotentAPI -Version 2.5.0 +PM> Install-Package IdempotentAPI -Version 2.6.0 ``` and, register the **IdempotentAPI Core services** for either controller-based APIs or minimal APIs. @@ -151,7 +151,7 @@ OR // Option 1: Define the default options: builder.Services.AddIdempotentMinimalAPI(new IdempotencyOptions()); -// Option 2: Configure the idempotent options by implementing the `IIdempotencyOptionsProvider` to provide the `IIdempotencyOptions` based on our needs (e.g., per endpoint). +// Option 2: Configure the idempotent options by implementing the `IIdempotencyOptionsProvider` to provide the `IIdempotencyOptions` based on our needs (e.g., per endpoint). For additional information, you can read the CHANGELOG.md. builder.Services.AddIdempotentMinimalAPI(new IdempotencyOptionsProvider()); ``` diff --git a/src/IdempotentAPI.MinimalAPI/IdempotentAPI.MinimalAPI.csproj b/src/IdempotentAPI.MinimalAPI/IdempotentAPI.MinimalAPI.csproj index daf5e88..c050d32 100644 --- a/src/IdempotentAPI.MinimalAPI/IdempotentAPI.MinimalAPI.csproj +++ b/src/IdempotentAPI.MinimalAPI/IdempotentAPI.MinimalAPI.csproj @@ -4,7 +4,7 @@ net7.0 Ioannis Kyriakidis ikyriakidis.com - 3.2.0-issue-81-01 + 3.2.0 IdempotentAPI support in Minimal APIs. cache;idempotent api;idempotency;asp.net core;attribute;middleware;rest https://github.com/ikyriak/IdempotentAPI.git diff --git a/src/IdempotentAPI/IdempotentAPI.csproj b/src/IdempotentAPI/IdempotentAPI.csproj index f5beb23..a451507 100644 --- a/src/IdempotentAPI/IdempotentAPI.csproj +++ b/src/IdempotentAPI/IdempotentAPI.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1 Ioannis Kyriakidis ikyriakidis.com - 2.6.0-issue-81-01 + 2.6.0 IdempotentAPI is an ASP.NET Core attribute by which any HTTP write operations (POST and PATCH) can have effect only once for the given request data. idempotent api;idempotency;asp.net core;attribute;middleware;rest https://github.com/ikyriak/IdempotentAPI.git diff --git a/tests/IdempotentAPI.TestWebMinimalAPIs/IdempotencyOptionsProvider.cs b/tests/IdempotentAPI.TestWebMinimalAPIs/IdempotencyOptionsProvider.cs index c466098..aa37b8f 100644 --- a/tests/IdempotentAPI.TestWebMinimalAPIs/IdempotencyOptionsProvider.cs +++ b/tests/IdempotentAPI.TestWebMinimalAPIs/IdempotencyOptionsProvider.cs @@ -1,6 +1,5 @@ ο»Ώusing IdempotentAPI.Core; using IdempotentAPI.MinimalAPI; -using IdempotentAPI.TestWebMinimalAPIs.ApiContext; using Microsoft.EntityFrameworkCore; namespace IdempotentAPI.TestWebMinimalAPIs @@ -13,7 +12,6 @@ public class IdempotencyOptionsProvider : IIdempotencyOptionsProvider private readonly List ExcludeRequestSpecialTypes = new() { typeof(DbContext), - typeof(ApiDbContext), }; public IIdempotencyOptions GetIdempotencyOptions(IHttpContextAccessor httpContextAccessor)