Skip to content

Instantly share code, notes, and snippets.

Vladimir Khorikov vkhorikov

Block or report user

Report or block vkhorikov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vkhorikov
vkhorikov / 1.cs
Last active Aug 22, 2019
You are naming your tests wrong
View 1.cs
[MethodUnderTest]_[Scenario]_[ExpectedResult]
@vkhorikov
vkhorikov / 1.cs
Created Jul 2, 2019
Decorators for both commands and queries
View 1.cs
public sealed class DatabaseCommandRetryDecorator<TCommand> : DatabaseRetryDecorator, ICommandHandler<TCommand>
where TCommand : ICommand
{
private readonly ICommandHandler<TCommand> _handler;
public DatabaseCommandRetryDecorator(ICommandHandler<TCommand> handler, Config config)
: base(config)
{
_handler = handler;
}
@vkhorikov
vkhorikov / 1.cs
Last active Jun 6, 2019
Merging domain events
View 1.cs
public sealed class Messages
{
private readonly IServiceProvider _provider;
public Messages(IServiceProvider provider)
{
_provider = provider;
}
public void Dispatch(IDomainEvent domainEvent)
@vkhorikov
vkhorikov / 1.cs
Last active Apr 15, 2019
CQRS and exception handling
View 1.cs
public class EditPersonalInfoCommandHandler : ICommandHandler<EditPersonalInfoCommand>
{
public Result Handle(EditPersonalInfoCommand command)
{
for (int i = 0; ; i++)
{
try
{
var unitOfWork = new UnitOfWork(_sessionFactory);
Student student = unitOfWork.GetStudentById(command.Id);
@vkhorikov
vkhorikov / 1.cs
Last active Feb 20, 2019
When to validate commands in CQRS
View 1.cs
public sealed class EnrollCommand : ICommand
{
public long StudentId { get; }
public string Course { get; }
public string Grade { get; }
public EnrollCommand(long studentId, string course, string grade)
{
if (course == null || grade == null) // Precondition checks
throw ArgumentException();
@vkhorikov
vkhorikov / 1.cs
Last active Jan 29, 2019
Are CQRS commands part of the domain model?
View 1.cs
public IActionResult EditPersonalInfo([FromBody] EditPersonalInfoCommand command)
{
var handler = new EditPersonalInfoCommandHandler(_unitOfWork);
Result result = handler.Handle(command);
return result.IsSuccess ? Ok() : Error(result.Error);
}
@vkhorikov
vkhorikov / full.cs
Last active Jul 9, 2019
Hierarchy of value objects - full code
View full.cs
public class Person : Entity
{
public virtual string Name { get; set; }
private readonly DocumentContainer _document;
public virtual Document Document
{
get => _document.Document;
set => _document.Document = value;
}
@vkhorikov
vkhorikov / 1.cs
Last active Dec 24, 2018
Hierarchy of value objects
View 1.cs
public class Person : Entity
{
public virtual string Name { get; set; }
public virtual Document Document { get; set; }
}
public class Document : Entity
{
}
@vkhorikov
vkhorikov / 1.cs
Last active Sep 8, 2018
In Defense of Lazy Loading
View 1.cs
public class Student : Entity
{
public virtual string Name { get; set; }
public virtual decimal TotalDebt { get; set; }
public virtual IList<Enrollment> Enrollments { get; set; }
public virtual IList<SportsActivity> SportsActivities { get; set; }
}
public class Enrollment : Entity
@vkhorikov
vkhorikov / 1.cs
Created Aug 11, 2018
Base entity class
View 1.cs
public abstract class Entity
{
public virtual long Id { get; protected set; }
protected virtual object Actual => this;
public override bool Equals(object obj)
{
var other = obj as Entity;
if (other is null)
You can’t perform that action at this time.