Use Case
A use case (interactor) holds one piece of application logic. It depends on ports (repositories, services), exposes an execute() returning a Result, and is called directly by a controller — no CQRS bus. This is the "simple path"; for complex domains use CQRS commands/queries instead.
Mark it @UseCase() (makes it injectable) and give it a Token:
import { UseCase } from '@soapjs/soap-express';
import { Inject, Result } from '@soapjs/soap';
@UseCase()
export class CreateComicUseCase {
static readonly Token = 'CreateComicUseCase';
constructor(@Inject(ComicRepository.Token) private readonly repo: ComicRepository) {}
async execute(input: CreateComicInput): Promise<Result<Comic>> {
const created = Comic.create({ id: randomUUID(), ...input });
if (created.isFailure()) return Result.withFailure(created.failure);
const result = await this.repo.add(created.content);
return result.isFailure() ? Result.withFailure(result.failure) : Result.withSuccess(result.content[0]);
}
}Bind it in the composition root, then inject it into a controller:
Last updated