Skip to content

Instantly share code, notes, and snippets.

View glen-84's full-sized avatar

Glen glen-84

  • Cape Town, South Africa
View GitHub Profile
@glen-84
glen-84 / hc-custom-filter.cs
Created May 15, 2023 14:32
HC custom filter WIP
public class EntityIdOperationFilterInputType : FilterInputType
{
protected override void Configure(IFilterInputTypeDescriptor descriptor)
{
descriptor
.Operation(DefaultFilterOperations.Equals)
.Type<LongType>();
}
}
@glen-84
glen-84 / AddTemporaryFileInputValidator.cs
Created February 2, 2024 13:14
HC validation example
public sealed class AddTemporaryFileInputValidator : AbstractValidator<AddTemporaryFileInput>
{
public AddTemporaryFileInputValidator()
{
this.RuleFor(f => f.TemporaryFileName)
.NotEmptyWithLength(FileName.MinimumLength, FileName.MaximumLength) // using VO metadata
.Must(FileName.ValidateCharacters) // using VO validation logic
.WithErrorCode(nameof(FileName.Errors.FileNameDisallowedCharacters)); // using VO validation message/code
}
}
@glen-84
glen-84 / IRepository.cs
Created February 2, 2024 13:39
Generic repository interface
public interface IRepository<TAggregateRoot> where TAggregateRoot : IAggregateRoot
{
public void Add(params TAggregateRoot[] entities);
public void Remove(params TAggregateRoot[] entities);
public Task<TAggregateRoot?> SingleOrDefaultAsync(
ISpecification<TAggregateRoot> specification,
CancellationToken cancellationToken = default);