BrandUp.Core
1.2.1
dotnet add package BrandUp.Core --version 1.2.1
NuGet\Install-Package BrandUp.Core -Version 1.2.1
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="BrandUp.Core" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BrandUp.Core --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BrandUp.Core, 1.2.1"
#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.
// Install BrandUp.Core as a Cake Addin #addin nuget:?package=BrandUp.Core&version=1.2.1 // Install BrandUp.Core as a Cake Tool #tool nuget:?package=BrandUp.Core&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
BrandUp.Core
Base framework for .NET development.
- Universal result structure
- CQRS infrastructure
Qieries
public class UserByPhoneQuery : IQuery<User>
{
[Required]
public string Phone { get; set; }
}
public class UserByPhoneQueryHandler : IQueryHandler<UserByPhoneQuery, User>
{
public Task<IList<User>> HandleAsync(UserByPhoneQuery query, CancellationToken cancellationToken = default)
{
var result = new List<User>
{
new User
{
Id = System.Guid.NewGuid(),
Phone = query.Phone
}
};
return Task.FromResult<IList<User>>(result);
}
}
serviceCollection.AddDomain(options =>
{
options.AddQuery<UserByPhoneQuery>();
})
.AddValidator<ComponentModelValidator>();
var userByPhoneResult = await domain.ReadAsync(new UserByPhoneQuery { Phone = "89232229022" });
// userByPhoneResult.IsSuccess
// userByPhoneResult.Errors
// userByPhoneResult.Data
// userByPhoneResult.Data[0]
Commands
public class SignUpCommandHandler : ICommandHandler<SignUpCommand, SignUpResult>
{
readonly IUserRepository userRepository;
public SignUpCommandHandler(IUserRepository userRepository)
{
this.userRepository = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
}
public async Task<SignUpResult> HandleAsync(SignUpCommand command, CancellationToken cancellationToken = default)
{
var user = new User
{
Id = System.Guid.NewGuid(),
Phone = command.Phone
};
await userRepository.CreateAsync(user, cancellationToken);
var result = new SignUpResult
{
User = user
};
return result;
}
}
public class SignUpCommand : ICommand<SignUpResult>
{
[Required]
public string Phone { get; set; }
}
public class SignUpResult
{
public User User { get; set; }
}
serviceCollection.AddDomain(options =>
{
options.AddCommand<SignUpCommandHandler>();
options.AddCommand<VisitUserCommandHandler>();
options.AddCommand<ChangeUserPhoneCommandHandler>();
})
.AddValidator<ComponentModelValidator>();
var domain = serviceProvider.GetRequiredService<IDomain>();
var signUpResult = await domain.SendAsync(new Example.Commands.SignUpCommandHandler { Phone = "+79231145449" });
// signUpResult.IsSuccess
// signUpResult.Errors
// signUpResult.Data
Items
public class User : IItem<Guid>
{
public Guid Id { get; set; }
public string Phone { get; set; }
}
public class UserProvider : IItemProvider<Guid, User>
{
public Task<User> FindByIdASync(Guid itemId, CancellationToken cancellationToken = default)
{
return Task.FromResult(new User { Id = new Guid("0b1eb946-c07c-406c-a7ba-d56b007c830a"), Phone = "79232229022" });
}
}
public class VisitUserCommand : IItemCommand<Items.User> { }
public class VisitUserCommandHandler : IItemCommandHandler<Items.User, VisitUserCommand>
{
public Task<Result> HandleAsync(Items.User item, VisitUserCommand command, CancellationToken cancellationToken = default)
{
return Task.FromResult(Result.Success());
}
}
serviceCollection.AddDomain(options =>
{
options.AddCommand<Example.Commands.VisitUserCommandHandler>();
})
.AddItemProvider<UserProvider>();
var domain = serviceProvider.GetRequiredService<IDomain>();
var item = await domain.FindItem<Guid, User>(new Guid("0b1eb946-c07c-406c-a7ba-d56b007c830a"));
var userProvider1 = serviceProvider.GetService<UserProvider>();
var userProvider2 = serviceProvider.GetService<IItemProvider<Guid, User>>();
var result = await domain.SendItemAsync(new Guid("0b1eb946-c07c-406c-a7ba-d56b007c830a"), new Example.Commands.VisitUserCommand());
var result = await domain.SendItemAsync(item, new Example.Commands.VisitUserCommand());
Results
Result.Success()
Result.Success<TData>(data)
Result.Error("code", "message")
Result.Error<TData>("code", "message")
Result.Error(...errors)
Result.Error<TData>(...errors)
// result.IsSuccess
// result.Errors
// result.Data
Product | Versions 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.