NexusX 1.1.2
dotnet add package NexusX --version 1.1.2
NuGet\Install-Package NexusX -Version 1.1.2
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="NexusX" Version="1.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NexusX" Version="1.1.2" />
<PackageReference Include="NexusX" />
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 NexusX --version 1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NexusX, 1.1.2"
#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 NexusX@1.1.2
#: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=NexusX&version=1.1.2
#tool nuget:?package=NexusX&version=1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NexusX
A .NET library for implementing the CQRS (Command Query Responsibility Segregation) pattern in a simple and efficient way.
🚀 Features
- ✅ Complete CQRS implementation - Commands, Queries and Notifications
- ✅ Commands with and without responses - Support for both patterns
- ✅ Pipeline Behaviors - Middleware for cross-cutting concerns
- ✅ Native Dependency Injection - Integration with Microsoft.Extensions.DependencyInjection
- ✅ Thread-safe - Safe for use in multi-threaded applications
- ✅ Performance optimized - Optimized reflection and type caching
- ✅ Robust error handling - Validations and well-defined exceptions
📦 Installation
dotnet add package NexusX
🔧 Configuration
1. Register in Program.cs
using Nexus;
var builder = WebApplication.CreateBuilder(args);
// Register Nexus with the assembly containing your handlers
builder.Services.AddNexus(typeof(Program).Assembly);
var app = builder.Build();
2. For multiple assemblies
builder.Services.AddNexus(
typeof(Program).Assembly,
typeof(YourCommand).Assembly
);
📝 Usage
Commands and Queries with Response
// 1. Create the Request
public class CreateUserCommand : IRequest<UserResponse>
{
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
}
// 2. Create the Handler
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, UserResponse>
{
public Task<UserResponse> Handle(CreateUserCommand request, CancellationToken cancellationToken)
{
// Your logic here
var user = new UserResponse
{
Id = Guid.NewGuid(),
Name = request.Name,
Email = request.Email
};
return Task.FromResult(user);
}
}
// 3. Use in Controller
[ApiController]
[Route("[controller]")]
public class UsersController : ControllerBase
{
private readonly INexus _nexus;
public UsersController(INexus nexus)
{
_nexus = nexus;
}
[HttpPost]
public async Task<UserResponse> Create(CreateUserCommand command)
{
return await _nexus.Send(command);
}
}
Commands without Response
// 1. Create the Command
public class DeleteUserCommand : IRequest
{
public Guid UserId { get; set; }
}
// 2. Create the Handler
public class DeleteUserCommandHandler : IRequestHandler<DeleteUserCommand>
{
public Task Handle(DeleteUserCommand request, CancellationToken cancellationToken)
{
// Your logic here - delete user from database
Console.WriteLine($"Deleting user {request.UserId}");
return Task.CompletedTask;
}
}
// 3. Use in Controller
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(Guid id)
{
await _nexus.Send(new DeleteUserCommand { UserId = id });
return NoContent();
}
Notifications
// 1. Create the Notification
public class UserCreatedNotification : INotification
{
public Guid UserId { get; set; }
public string Email { get; set; } = string.Empty;
}
// 2. Create the Handler
public class UserCreatedNotificationHandler : INotificationHandler<UserCreatedNotification>
{
public Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
{
// Send email, log, etc.
Console.WriteLine($"User {notification.UserId} created. Email: {notification.Email}");
return Task.CompletedTask;
}
}
// 3. Publish the Notification
await _nexus.Publish(new UserCreatedNotification
{
UserId = user.Id,
Email = user.Email
});
Pipeline Behaviors
// 1. Create the Behavior
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
Console.WriteLine($"Executing {typeof(TRequest).Name}");
var response = await next();
Console.WriteLine($"Completed {typeof(TRequest).Name}");
return response;
}
}
// 2. Register the Behavior
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
🐛 Debug
To check if your handlers are being registered correctly:
var app = builder.Build();
// List all registered handlers
app.Services.DebugRegisteredHandlers();
🔒 Security
The library includes several security validations:
- ✅ Null parameter validation
- ✅ Handler existence verification
- ✅ Reflection exception handling
- ✅ Public type validation
- ✅ Error handling in notifications
📄 License
MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please open an issue or pull request.
📞 Support
If you encounter any issues or have questions, please open an issue on GitHub.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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.
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 6.0.1)
-
net7.0
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.