Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.

Commit 606aaf7

Browse files
iscottb122Iain Scott
authored andcommitted
Use FromDomainObject and ToDomainObject mapping methods in readme.
1 parent 7a6e2ad commit 606aaf7

1 file changed

Lines changed: 56 additions & 6 deletions

File tree

README.md

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,22 @@ internal struct AccountDto
283283
public AccountTypeDto Type { get; }
284284

285285
...
286+
287+
public static AccountDto FromDomainObject(Account account)
288+
{
289+
return new AccountDto(
290+
(string)account.Id,
291+
new AccountTypeDto(account.Type.Name, account.Type.Rate),
292+
...);
293+
}
294+
295+
public Account ToDomainObject()
296+
{
297+
return new Account(
298+
(AccountId)Id,
299+
new AccountType(Type.Name, Type.Rate),
300+
...);
301+
}
286302
}
287303

288304
internal struct TransactionDto
@@ -306,6 +322,24 @@ internal struct TransactionDto
306322
public string Recipient { get; }
307323

308324
...
325+
326+
public static TransactionDto FromDomainObject(Transaction transaction)
327+
{
328+
return new TransactionDto(
329+
(string)transaction.Id,
330+
(string)transaction.Sender,
331+
(string)transaction.Recipient,
332+
...);
333+
}
334+
335+
public Transaction ToDomainObject()
336+
{
337+
return new Transaction(
338+
(TransactionId)Id,
339+
(AccountId)Sender,
340+
(AccountId)Recipient,
341+
...);
342+
}
309343
}
310344

311345
internal struct AccountTypeDto
@@ -326,6 +360,22 @@ internal struct AccountTypeDto
326360
public decimal Rate { get; }
327361

328362
...
363+
364+
public static AccountTypeDto FromDomainObject(AccountType accountType)
365+
{
366+
return new AccountTypeDto(
367+
accountType.Name,
368+
accountType.Rate,
369+
...);
370+
}
371+
372+
public AccountType ToDomainObject()
373+
{
374+
return new AccountType(
375+
Name,
376+
Rate,
377+
...);
378+
}
329379
}
330380
```
331381

@@ -335,18 +385,18 @@ The overloaded implementations of both `IEntityFacade` and `IValueObjectFacade`
335385
IEntityFacade<Account, AccountId, AccountDto> accountFacade = entityFacadeFactory.Create<Account, AccountId, AccountDto>(
336386
database,
337387
documentCollection,
338-
a => new AccountDto((string)a.Id, new AccountTypeDto(a.Type.Name, a.Type.Rate)),
339-
d => new Account((AccountId)d.Id, new AccountType(d.Type.Name, d.Type.Rate)));
388+
account => AccountDto.FromDomainObject(account),
389+
dto => dto.ToDomainObject());
340390
IEntityFacade<Transaction, TransactionId, TransactionDto> transactionFacade = entityFacadeFactory.Create<Transaction, TransactionId, TransactionDto>(
341391
database,
342392
documentCollection,
343-
t => new TransactionDto((string)t.Id, (string)t.Sender, (string)t.Recipient),
344-
d => new Transaction((TransactionId)d.Id, (AccountId)d.Sender, (AccountId)d.Recipient));
393+
transaction => TransactionDto.FromDomainObject(transaction),
394+
dto => dto.ToDomainObject());
345395
IValueObjectFacade<AccountType, AccountTypeDto> accountTypeFacade = valueObjectFacadeFactory.Create<AccountType, AccountTypeDto>(
346396
database,
347397
documentCollection,
348-
at => new AccountTypeDto(at.Name, at.Rate),
349-
d => new AccountType(d.Name, d.Rate));
398+
accountType => AccountTypeDto.FromDomainObject(accountType),
399+
dto => dto.ToDomainObject());
350400
```
351401

352402
The new repository implementations would then use the overloaded facade interfaces.

0 commit comments

Comments
 (0)