Unit of work

If you have a transactional boundary (job, command, message, request), model it as a scope.

Typical setup

  • Session/transaction: Lifetime.SCOPED

  • Repositories/services: Lifetime.TRANSIENT (they pull the current session from the scope)

Example (runnable)

See Scopes & cleanup and Resources (cleanup) for runnable scoped cleanup patterns.