Skip to content

Instantly share code, notes, and snippets.

View ivanpaulovich's full-sized avatar
🔀
#CleanArchitecture Manga 🍄

Ivan Paulovich ivanpaulovich

🔀
#CleanArchitecture Manga 🍄
View GitHub Profile
@ivanpaulovich
ivanpaulovich / Account.cs
Last active June 23, 2018 20:57
DDD-TDD-Rich-Domain
public sealed class Account : IEntity, IAggregateRoot
{
public Guid Id { get; private set; }
public Guid CustomerId { get; private set; }
public IReadOnlyCollection<ITransaction> GetTransactions()
{
IReadOnlyCollection<ITransaction> readOnly = _transactions.GetTransactions();
return readOnly;
}
public sealed class AccountCollection
{
private readonly IList<Guid> _accountIds;
public AccountCollection()
{
_accountIds = new List<Guid>();
}
public IReadOnlyCollection<Guid> GetAccountIds()
public sealed class Customer : IEntity, IAggregateRoot
{
public Guid Id { get; private set; }
public Name Name { get; private set; }
public SSN SSN { get; private set; }
public IReadOnlyCollection<Guid> Accounts
{
get
{
IReadOnlyCollection<Guid> readOnly = _accounts.GetAccountIds();
[Fact]
public void Customer_Should_Be_Loaded()
{
//
// Arrange
AccountCollection accounts = new AccountCollection();
accounts.Add(Guid.Empty);
Customer customer = Customer.Load(
Guid.Empty,
@ivanpaulovich
ivanpaulovich / SSN.cs
Last active June 24, 2018 16:00
A value object for the swedish Personnummer
public sealed class SSN
{
private string _text;
const string RegExForValidation = @"^\d{6,8}[-|(\s)]{0,1}\d{4}$";
public SSN(string text)
{
if (string.IsNullOrWhiteSpace(text))
throw new SSNShouldNotBeEmptyException("The 'SSN' field is required");
@ivanpaulovich
ivanpaulovich / DepositUseCase.cs
Created July 22, 2018 07:41
DepositUseCase.cs
public sealed class DepositUseCase : IDepositUseCase
{
private readonly IAccountReadOnlyRepository _accountReadOnlyRepository;
private readonly IAccountWriteOnlyRepository _accountWriteOnlyRepository;
public DepositUseCase(
IAccountReadOnlyRepository accountReadOnlyRepository,
IAccountWriteOnlyRepository accountWriteOnlyRepository)
{
_accountReadOnlyRepository = accountReadOnlyRepository;
@ivanpaulovich
ivanpaulovich / AccountsController.cs
Created July 22, 2018 09:39
AccountsController.cs
[Route("api/[controller]")]
public class AccountsController : Controller
{
private readonly IDepositUseCase _depositUseCase;
private readonly Presenter _presenter;
public AccountsController(
IDepositUseCase depositUseCase,
Presenter presenter)
{
@ivanpaulovich
ivanpaulovich / DepositPresenter.cs
Created July 22, 2018 09:44
DepositPresenter.cs
public class Presenter
{
public IActionResult ViewModel { get; private set; }
public void Populate(DepositOutput output)
{
if (output == null)
{
ViewModel = new NoContentResult();
return;
public class Module : Autofac.Module
{
public string ConnectionString { get; set; }
protected override void Load(ContainerBuilder builder)
{
var optionsBuilder = new DbContextOptionsBuilder<DbContext>();
optionsBuilder.UseSqlServer(ConnectionString);
optionsBuilder.EnableSensitiveDataLogging(true);
@ivanpaulovich
ivanpaulovich / autofac.entityframework.json
Created July 22, 2018 10:17
autofac.entityframework.json
{
"defaultAssembly": "Manga.Infrastructure",
"modules": [
{
"type": "Manga.Infrastructure.Modules.WebApiModule",
"properties": {
}
},
{
"type": "Manga.Infrastructure.Modules.ApplicationModule",