Response typing
Fluxzero allows you to formalize the expected return type of commands and queries by implementing the Request<R> interface. This lets the framework:
- Infer the response type at runtime and during testing
- Validate handler methods at compile-time (e.g.,
@HandleQuerymust return anR) - Simplify
queryAndWait(...)orsendCommand(...)invocations
Here’s an example for a query:
@Valuepublic class GetUserProfile implements Request<UserProfile> { String userId;
@HandleQuery UserProfile handle() { return loadProfile(userId); }}data class GetUserProfile(val userId: String) : Request<UserProfile> {
@HandleQuery fun handle(): UserProfile { return loadProfile(userId) }}Now, when calling this query, the return type is automatically known:
UserProfile profile = Fluxzero.queryAndWait(new GetUserProfile("123"));val profile = Fluxzero.queryAndWait(GetUserProfile("123"))When implementing Request<R>, the expected result type (R) is automatically inferred during testing and execution. This enables type-safe tests like:
testFixture.whenQuery(new GetUserProfile("123")) .expectResult(profile -> profile.getUserId().equals("123"));testFixture.whenQuery(GetUserProfile("123")) .expectResult { it.userId == "123" }If a class implements Request<R>, Fluxzero will use its declared generic type (R) to check that:
- A compatible handler exists
- The handler returns the correct result type
- The correct response is expected during testing
© 2026 Fluxzero