> For the complete documentation index, see [llms.txt](https://docs.soapjs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.soapjs.com/components/use-case.md).

# 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`:

```typescript
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:

```typescript
container.bindClass(CreateComicUseCase.Token, CreateComicUseCase);

// in the controller:
@Inject(CreateComicUseCase.Token) private readonly createComic: CreateComicUseCase;
const result = await this.createComic.execute(input);
```
