Skip to content

tiagor87/idempotency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quality Gate Status Coverage NuGet NuGet

Idempotency

This packages focuses on predicting the flows needed to use idempotency.

Idempotency.Core

Classes and interfaces required to use idempotency.

What's in the package

  • Interface IIdempotencyKeyReader

Interface responsible for identifying and reading the Request idempotence key.

  • Class IdempotencyKeyReader

Class with default implementation to obtain idempotency key. It uses the endpoint address, method, and key used in the Request. This way, it does not allow duplication by address, method and key.

public string Read(HttpRequest request)
{
  return $"[{request.Method}] {request.Path} - {request.Headers[IDEMPOTENCY_KEY_NAME]}";
}
  • Interface IIdempotencyRepository

Interface responsible for save and retrieve key and value from some storage.

  • Class IdempotencyRegister

Class relating to the registration of idempotency, it contains the key used, the status code returned in the operation and the response serialized JSON body.

  • Class IdempotencyMiddleware

Middleware responsible for inserting idempotency logic into the request flows of WebAPI applications.

How to install

  • .Net Cli
dotnet add package Idempotency.Core
  • Package Manager
Install-Package Idempotency.Core

How to use

In the Startup.cs file, add the following dependencies as scoped:

  • IIdempotencyKeyReader and implementation;
  • IIdempotencyRepository and implementation.
services.AddScoped<IIdempotencyKeyReader, IdempotencyKeyReader>();
services.AddScoped<IIdempotencyRepository, IdempotencyRepository>();

And the middleware IdempotencyMiddleware.

app.UseMiddleware<IdempotencyMiddleware>();

Idempotency.Redis

Class and extensions to use Redis as registers storage.

What's in the package

  • Class IdempotencyRepository

IIdempotencyRepository implementation that uses Redis as database.

  • Extensions Extensions

Extensions to add Services and Middleware to WebAPI.

How to install

  • .Net Cli
dotnet add package Idempotency.Redis
  • Package Manager
Install-Package Idempotency.Redis

How to use

To add services:

services.AddRedisIdempotency(Configuration);

To use middleware:

app.UseIdempotency();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages