Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands for ModuleDSL #110

Open
johanhaleby opened this issue Oct 24, 2021 · 1 comment
Open

Commands for ModuleDSL #110

johanhaleby opened this issue Oct 24, 2021 · 1 comment

Comments

@johanhaleby
Copy link
Owner

johanhaleby commented Oct 24, 2021

One idea would be to force the use of commands. This would allow one to do:

module {
	commands { c -> when(c) {
			is SomeCommand1 -> SomeDomainModel.handle(c.id, c)
			is SomeCommand2 -> SomeDomainModel.handle(c.id, c)
		}
	}
}

This would also work if the DM doesn't use commands:

module {
	commands { c -> when(c) {
			is SomeCommand1 -> SomeDomainModel.handle(c.id, c.thing1, c.thing2)
			is SomeCommand2 -> SomeDomainModel.handle(c.id, c.thing3)
		}
	}
}

It would also be possible to do:

module {
	commands(MyCommand::id, SomeDomainModle::handle)
}

if the DM handles all command types. Or if you have two different commands handlers (aggregates):

module {
	commands<GameCommand>(GameCommand::gameId, Game::handle)
	commands<PlayerCommand>(PlayerCommand::playerId, Player::handle)
}

Alternatively, if commands should only be defined once:

module {
        commands {
 			command<GameCommand>(GameCommand::gameId, Game::handle)
          	command<PlayerCommand>(PlayerCommand::playerId, Player::handle)
        }
}

An alternative. that is probably better, would be to pass the "aggregate id finder functions" to commands:

fun findId(cmd : Command) = when(cmd) {
	is GameCommand -> cmd.gameId
	is PlayerCommand -> cmd.playerId
}

module {
        commands(::findId) {
			command<GameCommand>(Game::handle)
			command<PlayerCommand>(Player::handle)
        }
}

Or maybe a combination? I.e. that you can pass "aggregate id finder functions" both to commands and command where command has precedence.

Note that module DSL should be lazy! Don't use subscription DSL etc directly in the module! (and interface would be ok!)

You compose modules into an Application, e.g.:

interface AllStartedGamesQuery : Query<AllStartedGamesDTO>

val module1 = module { .. } 
val module2 = module { .. } 

val applicationService = ..
val subscriptionDsl = ..
val domainQueryDsl = 

val application = application(module1, module2).start(applicationService, subscriptionDsl, domainQueryDsl)

application.dispatch(PlayGameCommand("gameId", Shape.Hand))
val allStartedGames = application.query<AllStartedGamesQuery>()
@johanhaleby
Copy link
Owner Author

How to handle integration events????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant