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
View 01.cs
public class Student : Entity
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
public int FavoriteCourseId { get; private set; } // Foreign key
}
public class Course : Entity
{
public string Title { get; private set; }
@vkhorikov
vkhorikov / 1.cs
Last active May 10, 2018
Value Objects and Identity
View 1.cs
public class PlanningTool
{
internal int Id { get; private set; }
// Rest of class
public ICollection<PlanningToolTab> Tabs { get; private set; }
}
public class PlanningToolTab
{
@vkhorikov
vkhorikov / 1.cs
Last active Mar 21, 2018
Non-determinism in tests
View 1.cs
public class SomeService
{
public void FirePeriodicJob()
{
/* Runs asynchronously */
}
}
@vkhorikov
vkhorikov / 1.cs
Last active Mar 20, 2018
Overriding methods in classes-dependencies
View 1.cs
public class StatisticsCalculator
{
public async Task<(double weightDelivered, double totalCost)> Calculate(int customerId)
{
List<DeliveryRecord> records = await GetDeliveries(customerId);
double weightDelivered = records.Sum(x => x.Weight);
double totalCost = records.Sum(x => x.Cost);
return (weightDelivered, totalCost);
@vkhorikov
vkhorikov / 1.cs
Last active Mar 19, 2018
Code pollution
View 1.cs
public class OrderRepository
{
public void Save(Order order)
{
/* ... */
}
public Order GetById(long id)
{
/* ... */
@vkhorikov
vkhorikov / 1.cs
Last active Feb 15, 2018
Using Value Objects to represent technical concerns
View 1.cs
public class Customer
{
public string Name { get; set; }
public string Email { get; set; }
}
Customer customer = GetCustomer();
customer.Name = customer.Email; // Compiles perfectly
@vkhorikov
vkhorikov / 1.cs
Last active Feb 16, 2018
Code Review: Value Objects and Error Messages
View 1.cs
public class AllowanceAmount : ValueObject
{
public const int MaxLength = 50;
public string Value { get; }
private AllowanceAmount(string value)
{
Value = value;
}
@vkhorikov
vkhorikov / 1.cs
Last active Jan 30, 2018
Leaking domain knowledge to tests
View 1.cs
public static class Calculator
{
public static int Add(int value1, int value2)
{
return value1 + value2;
}
}
@vkhorikov
vkhorikov / 1.cs
Last active Dec 5, 2017
NHibernate Async
View 1.cs
Customer customer = await session.GetAsync<Customer>(1);
@vkhorikov
vkhorikov / 1.cs
Last active Dec 2, 2017
.NET Value Type (struct) as a DDD Value Object
View 1.cs
public struct Email
{
public string Value { get; }
public bool IsConfirmed { get; }
public Email(string value, bool isConfirmed)
{
Value = value;
IsConfirmed = isConfirmed;
}
You can’t perform that action at this time.