# 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);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.soapjs.com/components/use-case.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
