Created
January 21, 2016 20:00
-
-
Save DominicFinn/49d1037f5df50a91c7ef to your computer and use it in GitHub Desktop.
Trying to stop a domain being abused
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using ImmutableDomain.Commands; | |
using ImmutableDomain.Entities; | |
using ImmutableDomain.Help; | |
namespace ImmutableDomain.Help | |
{ | |
public interface ICommandHandler<T> | |
{ | |
void Handle(T command); | |
} | |
public interface IRepository | |
{ | |
void Save<T>(T entity); | |
T Get<T>(Guid id); | |
} | |
} | |
namespace ImmutableDomain.Commands | |
{ | |
public sealed class CreateEmployeeCommand | |
{ | |
public readonly Guid Id; | |
public readonly string FirstName; | |
public readonly string LastName; | |
public CreateEmployeeCommand(Guid id, string firstName, string lastName) | |
{ | |
this.Id = id; | |
this.FirstName = firstName; | |
this.LastName = lastName; | |
} | |
} | |
} | |
namespace ImmutableDomain.Entities | |
{ | |
public sealed class Employee | |
{ | |
public Guid Id { get; private set; } | |
public string FirstName { get; private set; } | |
public string LastName { get; private set; } | |
internal Employee(Guid id, string firstName, string lastName) | |
{ | |
Id = id; | |
FirstName = firstName; | |
LastName = lastName; | |
} | |
} | |
internal interface IEditableEmployee | |
{ | |
void Update(string firstName, string lastName); | |
} | |
} | |
namespace ImmutableDomain.CommandProcessors | |
{ | |
internal sealed class CreateEmployeeCommandHandler : ICommandHandler<CreateEmployeeCommand> | |
{ | |
private readonly IRepository repository; | |
internal CreateEmployeeCommandHandler(IRepository repository) | |
{ | |
this.repository = repository; | |
} | |
public void Handle(CreateEmployeeCommand command) | |
{ | |
var employee = new Employee(command.Id, command.FirstName, command.LastName); | |
this.repository.Save(employee); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment