Skip to content

SAIF.Framework.Data.NHibernate overview

Documentation context: Packaged Component (NuGet)

SAIF.Framework.Data.NHibernate is a layered NHibernate ORM data-access library that implements and consumes — rather than defines — the unit-of-work/repository/session seam used by consuming applications, together with 42 FluentNHibernate entity mappings across 10 domain areas. The seam contracts — IUnitOfWork, IRepository<TEntity>, ISessionHelper, and IDataEntity — are supplied by the SAIF.Framework.Core package dependency (namespace SAIF.Data), not by the consuming application: this project's RootNamespace (SAIF.Data.NHibernate) nests under Core's SAIF.Data namespace, so C# enclosing-namespace lookup brings Core's types into scope without a using directive. This project's own SAIF.Data.NHibernate.Interfaces namespace is unrelated and holds only its 3 locally-declared interfaces (IConfigurationFactory, ISessionStrategy, IUnitOfWorkFactory).

Purpose

  • Provides engine-specific (Oracle and SQL Server) configuration and unit-of-work factories that build and cache NHibernate Configuration/ISessionFactory instances and hand out transaction-scoped units of work.
  • Provides a generic CRUD/query repository surface (Add/Update/Delete/Query/Get/Load/SystemDate) usable against any entity mapped in the assembly, abstracting over stateful (ISession) and stateless (IStatelessSession) NHibernate session semantics behind a common ISessionStrategy seam.
  • Declaratively maps 42 entities from the SAIF.Data.Model.* namespaces to their relational schema via FluentNHibernate ClassMap<TEntity> classes, discovered by assembly scanning rather than direct external consumption.
  • Consumed by applications that need to wire up dependency injection against IConfigurationFactory/IUnitOfWorkFactory/ISessionStrategy to obtain database access for the 42 mapped entities.

Responsibilities

  • Build and cache engine-specific NHibernate configurations and session factories keyed by connection string.
  • Own the unit-of-work transaction boundary (Begin()/Commit()/Rollback()).
  • Provide generic repository CRUD/query operations over either session strategy.
  • Supply engine-specific server-time retrieval with a local-clock fallback.
  • Provide one domain-specific extension (ImageRepositoryExtensions) for Oracle sequence-based ID generation in the Imaging domain.

Key components

  • IConfigurationFactory / ConfigurationFactoryBase / OracleConfigurationFactory / SqlServerConfigurationFactory: build and cache engine-specific NHibernate Configuration/ISessionFactory instances.
  • IUnitOfWorkFactory / UnitOfWorkFactoryBase / OracleUnitOfWorkFactory / OracleStatelessUnitOfWorkFactory / SqlServerUnitOfWorkFactory: construct NHibernateUnitOfWork instances per engine/session-strategy combination.
  • NHibernateUnitOfWork: owns the transaction boundary and hands out Repository<TEntity> instances.
  • Repository<TEntity> / RepositoryBase<TEntity>: generic CRUD + LINQ query surface over ISessionStrategy.
  • ImageRepositoryExtensions: Oracle sequence-based ID generation extension methods for the Imaging domain.
  • Mappings/: 42 ClassMap<TEntity> classes across 10 domain sub-folders (Contacts, Deployment, Employee, Imaging, Menu, PDF, Preferences, Printing, Users, WebContext).

Sources

  • SAIF.Framework.Data.NHibernate.csproj
  • SAIF.Framework.Data.NHibernate.nuspec