Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil.jedrzejuk committed Oct 9, 2024
1 parent c4af2f6 commit cdc8b44
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ The project follows **Domain-Driven Design (DDD)** principles, which structure t
Transaction management is handled using a lambda function that wraps database operations in a transactional context.

```kotlin
fun <T> executeInTransaction(block: () -> T): T {
return inTransaction(block as () -> Any) as T
fun <T> inTransaction(block: () -> T): T {
return executeInTransaction(block as () -> Any) as T
}

private var inTransaction: (() -> Any) -> Any = { block -> block() }
private var executeInTransaction: (() -> Any) -> Any = { block ->
block()
}

@Configuration
class TransactionManagerConfig {

@PostConstruct
fun setupProductionTransaction() {
inTransaction = { block -> transaction { block() } }
executeInTransaction = { block ->
transaction { block() }
}
}
}
```
Expand All @@ -61,7 +65,7 @@ fun create(command: CreateAccountCommand): AccountSnapshot {
}
val id = repository.nextAccountId()
val account = Account.createNewAccount(command.toCreateAccountData(id))
executeInTransaction {
inTransaction {
repository.save(account)
val events = account.getEvents()
accountOperationRepository.save(events)
Expand Down

0 comments on commit cdc8b44

Please sign in to comment.