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: about 1 month 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.
- Host: GitHub
- URL: https://github.com/jomaxso/segres
- Owner: jomaxso
- License: mit
- Created: 2022-03-23T14:57:13.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T20:26:00.000Z (over 3 years ago)
- Last Synced: 2026-02-24T19:40:01.445Z (3 months ago)
- Topics: asp-net-core, aspnet-web-api, aspnetcore, dotnet, dotnet-core, dotnet7, mediation, minimal-api, net7, pubsub, sender-reciever
- Language: C#
- Homepage:
- Size: 452 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
SEGRES
The simple way to segerate your responsibilities.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
[](https://www.nuget.org/packages/Segres/)
[](https://www.nuget.org/packages/Segres/)
[](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.