An open API service indexing awesome lists of open source software.

https://github.com/jomaxso/segres

A mediator library for .Net using strongly-typed handler implementations. It provides a synchronise and asynchronise api, which is optimized for speed and memory.
https://github.com/jomaxso/segres

asp-net-core aspnet-web-api aspnetcore dotnet dotnet-core dotnet7 mediation minimal-api net7 pubsub sender-reciever

Last synced: 6 months ago
JSON representation

A mediator library for .Net using strongly-typed handler implementations. It provides a synchronise and asynchronise api, which is optimized for speed and memory.

Awesome Lists containing this project

README

          







Segres

SEGRES


The simple way to segerate your responsibilities.




Explore the docs »





View Demo
·
Report Bug
·
Request Feature

[![NuGet version](https://badgen.net/nuget/v/Segres)](https://www.nuget.org/packages/Segres/)
[![NuGet downloads](https://badgen.net/nuget/dt/Segres)](https://www.nuget.org/packages/Segres/)
[![Test status](https://badgen.net/github/checks/jomaxso/Segres/master/test)](https://www.nuget.org/packages/Segres/)

A mediator library for .Net using strongly-typed handler implementations. It provides a synchronise and asynchronise api, which is optimized for speed and memory.

## Getting Started

Segres can be installed using the Nuget package manager or the dotnet CLI.

```shell
dotnet add package Segres
```

Explore the documentation for instructions on how to use the package.

## Example

### Segres
#### Register all dependencies

```csharp
// Program.cs

using Segres

...

builder.Services.AddSegres();

...

```

### Segres.Abstractions
#### Create a handler

```csharp
// CreateCustomerRequestHandler.cs

using Segres;

public record CreateCustomerRequest(string Firstname, string Lastname) : IRequest;

public sealed class CreateCustomerRequestHandler : IRequestHandler
{
public async ValueTask HandleAsync(CreateCustomerRequest request, CancellationToken cancellationToken)
{
await ValueTask.CompletedTask;
return Guid.NewGuid();
}
}
```

#### Send a request

```csharp
// SomeService.cs

using Segres;

public class SomeService
{
private readonly IMediator _mediator;

public SomeService(IMediator mediator)
{
_mediator = mediator;
}

...

public async ValueTask SomeMethodAsync(CancellationToken cancellationToken)
{
var request = new CreateCustomerRequest("Peter", "Parker");
Guid id = await _mediator.SendAsync(request, cancellationToken);
return id;
}
}

```

### Segres.AspNetCore

#### Register all endpoints

```csharp
// Program.cs

using Segres

...

app.UseSegres();

...

```

#### Create a request

```csharp
// CreateUserRequest.cs

public record CreateUserRequest() : IHttpRequest
{
public static string EndpointRoute => "/create";
public static RequestType RequestType => RequestType.Post;
}
```

#### Create an endpoint for a request

```csharp
// CreateUserEndpoint.cs

public sealed class CreateUserEndpoint : AbstractEndpoint
{
public override async ValueTask> ResolveAsync(CreateUserRequest request, CancellationToken cancellationToken)
{
int result = await ...
return Ok(result)
}
}
```
_For more examples, please refer to the [Documentation](#)_

## License

Distributed under the MIT License. See `LICENSE.md` for more information.