Package com.guinetik.hexafun.hexa
Class UseCaseBuilder
java.lang.Object
com.guinetik.hexafun.hexa.UseCaseBuilder
Builder for creating HexaApp instances with use cases, ports, and adapters.
Supports fluent DSL with implicit closure - each useCase() call automatically closes the previous one.
Example:
HexaFun.dsl()
.withPort(TaskRepository.class, new InMemoryTaskRepository())
.withAdapter(TO_DTO, task -> new TaskDTO(task.id(), task.title()))
.useCase(Keys.CREATE)
.validate(validator)
.handle(handler)
.useCase(Keys.DELETE)
.handle(deleteHandler)
.build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build a HexaApp with all the registered use cases and ports.<I,O> UseCaseInputStep<I, O> useCase(UseCaseKey<I, O> key) Start defining a use case with a type-safe key.<From,To> UseCaseBuilder withAdapter(AdapterKey<From, To> key, Function<From, To> adapter) Register an adapter with a type-safe key.<T> UseCaseBuilderRegister a port (output adapter) by its type.
-
Constructor Details
-
UseCaseBuilder
public UseCaseBuilder()
-
-
Method Details
-
withPort
Register a port (output adapter) by its type. Ports are registered when build() is called.Example:
HexaFun.dsl() .withPort(TaskRepository.class, new InMemoryTaskRepository()) .withPort(EmailService.class, new SmtpEmailService()) .useCase(...) .build();- Type Parameters:
T- The port type- Parameters:
type- The interface/class type to registerimpl- The implementation instance- Returns:
- This builder for chaining
-
withAdapter
Register an adapter with a type-safe key. Adapters transform data from one type to another.Example:
HexaFun.dsl() .withAdapter(TO_INVENTORY, req -> new InventoryCheck(req.itemId())) .withAdapter(TO_PAYMENT, req -> new PaymentRequest(req.total())) .useCase(...) .build();- Type Parameters:
From- The source typeTo- The target type- Parameters:
key- The type-safe adapter keyadapter- The transformation function- Returns:
- This builder for chaining
-
useCase
Start defining a use case with a type-safe key. Implicitly closes any previous use case definition.- Type Parameters:
I- The input type of the use caseO- The output type of the use case- Parameters:
key- The type-safe key for this use case- Returns:
- A new UseCaseInputStep for chaining
-
build
Build a HexaApp with all the registered use cases and ports.- Returns:
- A new HexaApp instance
-