SuperMediaR 1.0.5

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package SuperMediaR --version 1.0.5
                    
NuGet\Install-Package SuperMediaR -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SuperMediaR" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SuperMediaR" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="SuperMediaR" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SuperMediaR --version 1.0.5
                    
#r "nuget: SuperMediaR, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SuperMediaR@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SuperMediaR&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=SuperMediaR&version=1.0.5
                    
Install as a Cake Tool

SuperMediaR

SuperMediaR é um Mediator leve, extensível e moderno para .NET 8+, com suporte a padrões como CQRS, Pipeline Behaviors e integração com EF Core. Ideal para aplicações complexas com separação de responsabilidades clara e escalável.

✨ Recursos

  • Suporte a Commands, Queries e Events
  • Pipeline Behaviors com suporte a:
    • ✔️ Validação (via FluentValidation)
    • ✔️ Logging
    • ✔️ Autorização (com roles e regras customizadas)
    • ✔️ Caching para queries
    • ✔️ Transações com EF Core
    • ✔️ Dispatcher de eventos após execução
  • Suporte a múltiplos Handlers
  • Pronto para ser injetado com Dependency Injection
  • Separação entre modelos de leitura e escrita (CQRS)

⚙️ Configuração

1. Adicione no seu Program.cs:

builder.Services.AddSuperMediaR();

2. Configure o DbContext, FluentValidation e ILogger normalmente:

builder.Services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddValidatorsFromAssemblyContaining<CreateUserValidator>();

builder.Services.AddLogging();

💡 Exemplo de Uso

1. Criando um Command

public record CreateUserCommand(string Name, string Email) : ICommand<Guid>;

2. Criando o Handler

public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, Guid>
{
    private readonly MyDbContext _context;

    public CreateUserCommandHandler(MyDbContext context)
    {
        _context = context;
    }

    public async Task<Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
    {
        var user = new User { Id = Guid.NewGuid(), Name = request.Name, Email = request.Email };
        _context.Users.Add(user);
        await _context.SaveChangesAsync(cancellationToken);
        return user.Id;
    }
}

3. Chamando o Mediator

var userId = await _mediator.SendAsync(new CreateUserCommand("John", "john@email.com"));

🔐 Autorização com Roles e Regras

Criando uma regra customizada

public class MustBeAdminRule : IAuthorizationRule<CreateUserCommand>
{
    private readonly IUserContext _userContext;

    public MustBeAdminRule(IUserContext userContext)
    {
        _userContext = userContext;
    }

    public Task<bool> IsAuthorizedAsync(CreateUserCommand request, CancellationToken cancellationToken)
    {
        return Task.FromResult(_userContext.Roles.Contains("Admin"));
    }
}

🔄 Cache de Queries

Basta implementar a interface ICacheableQuery na query que deseja cachear:

public record GetUserByIdQuery(Guid Id) : IQuery<UserDto>, ICacheableQuery
{
    public string CacheKey => $"user:{Id}";
    public TimeSpan? Expiration => TimeSpan.FromMinutes(10);
}

📢 Eventos

public record UserCreatedEvent(Guid UserId) : IEvent;

public class UserCreatedEventHandler : IEventHandler<UserCreatedEvent>
{
    public Task HandleAsync(UserCreatedEvent @event, CancellationToken cancellationToken)
    {
        Console.WriteLine($"Novo usuário criado: {@event.UserId}");
        return Task.CompletedTask;
    }
}

Os eventos são disparados após o CommandHandler, se definidos no EventDispatcherBehavior.


🧪 Testes

Todos os handlers podem ser testados isoladamente. Basta mockar dependências e chamar diretamente o método Handle.


🤝 Contribuindo

Contribuições são bem-vindas! Sinta-se livre para abrir issues ou pull requests.


📄 Licença

Este projeto é licenciado sob a MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated