![]() |
VOOZH | about |
dotnet add package Idempwanna --version 1.0.0
NuGet\Install-Package Idempwanna -Version 1.0.0
<PackageReference Include="Idempwanna" Version="1.0.0" />
<PackageVersion Include="Idempwanna" Version="1.0.0" />Directory.Packages.props
<PackageReference Include="Idempwanna" />Project file
paket add Idempwanna --version 1.0.0
#r "nuget: Idempwanna, 1.0.0"
#:package Idempwanna@1.0.0
#addin nuget:?package=Idempwanna&version=1.0.0Install as a Cake Addin
#tool nuget:?package=Idempwanna&version=1.0.0Install as a Cake Tool
Idempwanna is an abstract idempotency feature for ASP.NET projects that can be used with different types of caching offerings in the .NET Core framework.
Idempotency is the property of certain operations whereby they can be applied multiple times without changing the result beyond the initial application. In web APIs, this means that making the same request multiple times has the same effect as making it once.
[IdempotentKey] attributedotnet add package Idempwanna
Register the idempotency services in your Program.cs or Startup.cs:
// Using in-memory cache (simplest approach)
builder.Services.AddIdempotency()
.WithInMemoryCache();
// Or with custom options
builder.Services.AddIdempotency()
.WithInMemoryCache(options =>
{
options.DefaultCacheExpiration = TimeSpan.FromHours(1);
options.DefaultHeaderName = "x-idempotency-key";
options.ThrowOnMissingKey = true;
});
// Or with a custom cache implementation
builder.Services.AddIdempotency()
.WithCustomCache<YourCustomCacheImplementation>();
// Advanced configuration using method chaining
builder.Services.AddIdempotency()
.WithCustomCache<RedisIdempotencyCache>()
.WithKeyGenerator<CustomKeyGenerator>()
.WithService<CustomIdempotencyService>()
.Configure(options =>
{
options.AllowBodyBasedKeys = true;
options.AllowQueryParameterKeys = true;
});
Use the [Idempotent] attribute on your controller actions:
[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
[HttpPost]
[Idempotent] // This makes the endpoint idempotent
public async Task<ActionResult<OrderResponse>> CreateOrder(OrderRequest request)
{
// Your implementation here
// The idempotency is handled automatically by the attribute
return Ok(new OrderResponse { /* ... */ });
}
}
If you need more control, you can use the IIdempotencyService directly:
[ApiController]
[Route("api/[controller]")]
public class PaymentsController : ControllerBase
{
private readonly IIdempotencyService _idempotencyService;
private readonly IIdempotencyKeyGenerator _keyGenerator;
public PaymentsController(
IIdempotencyService idempotencyService,
IIdempotencyKeyGenerator keyGenerator)
{
_idempotencyService = idempotencyService;
_keyGenerator = keyGenerator;
}
[HttpPost]
public async Task<ActionResult<PaymentResponse>> ProcessPayment(PaymentRequest request)
{
// Generate a key from the request
var idempotencyKey = _keyGenerator.GenerateKey(request);
// Use the idempotency service to process the request
var response = await _idempotencyService.ProcessAsync<PaymentResponse>(
idempotencyKey,
async cancellationToken =>
{
// This will only execute if this is not a duplicate request
PaymentResponse result = await ProcessPaymentLogic(request);
return result;
});
return Ok(response);
}
}
You can mark specific parameters to be used as idempotency keys using the [IdempotentKey] attribute:
[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
[HttpPost("{requestId}")]
[Idempotent]
public async Task<ActionResult<OrderResponse>> CreateOrder(
[IdempotentKey] Guid requestId,
OrderRequest request)
{
// The requestId parameter will be used as the idempotency key
// No need to extract it from headers or generate it from the request body
return Ok(new OrderResponse { /* ... */ });
}
}
This is particularly useful for operations where you want to use a client-generated ID as the idempotency key, such as in distributed systems or event-driven architectures.
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on Idempwanna:
| Package | Downloads |
|---|---|
|
Corban.Internal.AspNet
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 362 | 5/20/2025 |