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 the runnable script in Patterns (Repository / unit-of-work pattern section).