Xpandables.Net.BlazorExtended
6.1.1
dotnet add package Xpandables.Net.BlazorExtended --version 6.1.1
NuGet\Install-Package Xpandables.Net.BlazorExtended -Version 6.1.1
<PackageReference Include="Xpandables.Net.BlazorExtended" Version="6.1.1" />
paket add Xpandables.Net.BlazorExtended --version 6.1.1
#r "nuget: Xpandables.Net.BlazorExtended, 6.1.1"
// Install Xpandables.Net.BlazorExtended as a Cake Addin #addin nuget:?package=Xpandables.Net.BlazorExtended&version=6.1.1 // Install Xpandables.Net.BlazorExtended as a Cake Tool #tool nuget:?package=Xpandables.Net.BlazorExtended&version=6.1.1
Xpandables.Net
Provides with useful interfaces contracts in .Net 6.0 and some implementations mostly following the spirit of SOLID principles, CQRS... The library is strongly-typed, which means it should be hard to make invalid requests and it also makes it easy to discover available methods and properties though IntelliSense.
Feel free to fork this project, make your own changes and create a pull request.
Read the Xpandables.Net.Samples for a minimal Web Api implementation using multi-tenancy with aggregates. You may need to create a PostgreSql database using the migration definitions.
Features
Usually, when registering types, we are forced to reference the libraries concerned and we end up with a very coupled set. To avoid this, you can register these types by calling an export extension method, which uses MEF: Managed Extensibility Framework.
In your api startup class
// AddXServiceExport(IConfiguration, Action{ExportServiceOptions}) adds and configures registration of services using
// the IAddServiceExport interface implementation found in the target libraries according to the export options.
// You can use configuration file to set up the libraries to be scanned.
public class Startup
{
....
services
.AddXpandableServices()
.AddXServiceExport(Configuration, options => options.SearchPattern = "your-search-pattern-dll")
.Build();
...
}
In the library you want types to be registered
[Export(typeof(IAddServiceExport))]
public sealed class RegisterServiceExport : IAddServiceExport
{
public void AddServices(IServiceCollection services, IConfiguration configuration)
{
services
.AddXpandableServices()
.AddXCommandDispatcher()
...
.Build();
....
}
}
Decorator pattern
You can use the extension methods to apply the decorator pattern to your types.
// This method and its extensions ensure that the supplied TDecorator" decorator is returned, wrapping the original
// registered "TService", by injecting that service type into the constructor of the supplied "TDecorator".
// Multiple decorators may be applied to the same "TService". By default, a new "TDecorator" instance
// will be returned on each request,
// independently of the lifestyle of the wrapped service. Multiple decorators can be applied to the same service type.
// The order in which they are registered is the order they get applied in. This means that the decorator
// that gets registered first, gets applied first, which means that the next registered decorator,
// will wrap the first decorator, which wraps the original service type.
services
.AddXpandableServices()
.XTryDecorate<TService, TDecorator>()
.Build();
Suppose you want to add logging for the AddPersonCommand ...
// The AddPersonCommand decorator for logging
public sealed class AddPersonCommandHandlerLoggingDecorator :
ICommandHandler<AddPersonCommand>
{
private readonly ICommandHandler<AddPersonCommand> _decoratee;
private readonly ILogger<AddPersonCommandHandler> _logger;
public AddPersonCommandHandlerLoggingDecorator(
ILogger<AddPersonCommandHandler> logger,
ICommandHandler<AddPersonCommand> decoratee)
=> (_logger, _decoratee) = (logger, decoratee);
public async ValueTask<OperationResult> HandleAsync(
AddPersonCommand command, CancellationToken cancellationToken = default)
{
_logger.Information(...);
var response = await _decoratee.HandleAsync(command, cancellationToken).configureAwait(false);
_logger.Information(...)
return response;
}
}
// Register
services
.AddXpandableServices()
.XTryDecorate<AddPersonCommandHandler, AddPersonCommandHandlerLoggingDecorator>()
.Build();
// or
services.AddXpandableServices()
.AddXHandlers(
options =>
{
options.UseValidatorDecorator(); // this option will add the command decorator registration
},
typeof(AddPersonCommandHandler).Assembly)
.Build()
// or you can define the generic model, for all commands that implement ICommand
// interface or something else.
public sealed class CommandLoggingDecorator<TCommand> : ICommandHandler<TCommand>
where TCommand : notnull, ICommand // you can add more constraints
{
private readonly ICommandHandler<TCommand> _ decoratee;
private readonly ILogger<TCommand> _logger;
public CommandLoggingDecorator(ILogger<TCommand> logger, ICommandHandler<TCommand> decoratee)
=> (_logger, _ decoratee) = (logger, decoratee);
public async ValueTask<OperationResult> HandleAsync(
TCommand command, CancellationToken cancellationToken = default)
{
_logger.Information(...);
var response = await _decoratee.HandleAsync(command, cancellationToken).configureAwait(false);
_logger.Information(...)
return response;
}
}
// and for registration
// The CommandLoggingDecorator will be applied to all command handlers whose commands meet
// the decorator's constraints :
// To be a notnull and implement ICommand interface
services
.AddXpandableServices()
.XTryDecorate(typeof(ICommandHandler<>), typeof(CommandLoggingDecorator<>))
.Build();
Aggregate{TAggregateId}
Libraries also provide with DDD model implementation 'Aggregate{TAggregateId}' using event sourcing and out-box pattern.
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 was computed. 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 was computed. 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. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.7)
- Xpandables.Net (>= 6.1.1)
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 |
---|---|---|
6.1.1 | 872 | 8/6/2022 |
6.0.9 | 870 | 7/9/2022 |
6.0.8 | 843 | 6/27/2022 |
6.0.4 | 866 | 3/15/2022 |
6.0.3 | 893 | 2/22/2022 |
6.0.2 | 691 | 1/4/2022 |
6.0.1 | 707 | 12/4/2021 |
6.0.0 | 724 | 11/8/2021 |
6.0.0-rc.4.3 | 161 | 11/3/2021 |
6.0.0-rc.3.1 | 171 | 10/15/2021 |
6.0.0-rc.3 | 161 | 10/14/2021 |
6.0.0-rc.2 | 162 | 9/21/2021 |
6.0.0-preview.5 | 158 | 8/26/2021 |
5.6.1 | 799 | 6/30/2021 |
5.6.0 | 766 | 6/9/2021 |
5.5.1 | 754 | 5/26/2021 |
Fix IEventStore implementation