---
title: IUnitOfWorkFactory
summary: API reference for IUnitOfWorkFactory.
status: draft
owner: Framework
last_reviewed: 2026-09-15
library: SAIF.Framework.Data.NHibernate
reference_type: package
---

# IUnitOfWorkFactory

`IUnitOfWorkFactory` is the seam contract consuming applications depend on to obtain a `NHibernateUnitOfWork` for a connection string, without needing to know which database engine or session strategy (stateful/stateless) the concrete factory (`OracleUnitOfWorkFactory`, `OracleStatelessUnitOfWorkFactory`, `SqlServerUnitOfWorkFactory`) uses.

## Purpose
- Defines the single operation (`GetUnitOfWork`) consumers call to obtain a transaction-scoped unit of work bound to a freshly opened NHibernate session.
- Allows application code to depend on this interface for dependency injection rather than a concrete engine-specific factory class.

## Context
- Namespace: `SAIF.Data.NHibernate`
- Assembly/package: `SAIF.Framework.Data.NHibernate`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| GetUnitOfWork | `NHibernateUnitOfWork GetUnitOfWork(string connectionString, int batchSize, bool showSql)` | Resolves (or builds and caches) an `ISessionFactory` for `connectionString`, opens a session appropriate to the implementation's engine/session-strategy combination, and returns a `NHibernateUnitOfWork` wrapping it. |

## Behavioral notes
- Every call returns a **new** `NHibernateUnitOfWork` bound to a freshly opened session — the `ISessionFactory` is cached and reused, but the session/unit-of-work is not (see [BR-005](../../business-rules.md#br-005-repository-is-scoped-to-one-unit-of-work)).

## Constraints and usage notes
- Implementers must be constructed with a matching `IConfigurationFactory` so the session factory targets the correct database engine.

## Sources
- `Interfaces/IUnitOfWorkFactory.cs`
- `Factories/UnitOfWorkFactoryBase.cs`
