SAIF.NetCore.NHibernate overview¶
Documentation context: Packaged Component (NuGet)
SAIF.NetCore.NHibernate is the repository's NHibernate data-access infrastructure provider: it defines the IUnitOfWork/IUnitOfWorkFactory/IRepository<TEntity>/ISessionStrategy stack, a named-options configuration model (UnitOfWorkOptions/ConfigureUnitOfWorkOptions), and per-engine driver configurations for Oracle, SQL Server, and PostgreSQL built on FluentNHibernate, but it ships no entity mappings or business schema of its own — consuming applications supply those.
Purpose¶
- Provide a reusable Unit of Work and generic Repository abstraction over NHibernate so that consuming applications do not have to hand-roll session, transaction, and configuration management for Oracle, SQL Server, or PostgreSQL.
- Supply a named-options configuration pattern (
UnitOfWorkOptions/ConfigureUnitOfWorkOptions) through which a consuming application resolves connection strings and environment settings viaIEnvironmentClient/IDBConnectionClient(both fromSAIF.NetCore.ServiceContracts). - Offer both stateful (change-tracking) and stateless (bulk-throughput) NHibernate session strategies behind one
ISessionStrategycontract. - No application or library in this repository currently references this package* —
SAIF.NetCore.ServiceExtensionsdoes not bring it in transitively even though the top-level architecture diagram draws a composition arrow from ServiceExtensions to the data group; consuming applications must referenceSAIF.NetCore.NHibernatedirectly, and this is a documented discrepancy between the diagram and the actual package graph*.
Responsibilities¶
- Build and cache an NHibernate
ISessionFactoryper connection string, selecting the Oracle, SQL Server, or PostgreSQL driver configuration fromUnitOfWorkOptions.Database. - Manage the transaction lifecycle at
ReadCommittedisolation (Begin/Commit/Rollback/Dispose).Beginis refused while a transaction is already active. One unit of work per transaction is the recommended usage, but the library does not enforce it. - Discover consumer-supplied Fluent
ClassMap<T>and embedded HBM mappings by assembly scan when a session factory is built. - Register the modern DI surface (
AddNhibernateServices) while retaining 13 legacy registration methods as[Obsolete("Due to functional changes between .net core 2.2 and .net core 3.1, this method is obsolete to avoid startup errors.", true)]compile-time errors for migration enforcement. - Expose an engine-specific database system-date query (
SystemDate) throughISessionHelperimplementations.
Key components¶
UnitOfWorkFactory: builds and cachesISessionFactoryinstances per connection string and hands outIUnitOfWorkinstances.UnitOfWork: the transaction boundary (Begin/Commit/Rollback/Dispose) and repository factory.Repository<TEntity>: generic CRUD/query pass-through to the activeISessionStrategy.ISessionStrategy(StatefulSessionStrategy/StatelessSessionStrategy): adapts NHibernate'sISession/IStatelessSessionto one contract.BaseConfiguration(OracleConfiguration/SqlConfiguration/PostGreSqlConfiguration): per-engine FluentNHibernate driver configuration.UnitOfWorkOptions/ConfigureUnitOfWorkOptions: the named-options model a consuming application subclasses per logical database.
Related documentation¶
- Index
- Architecture
- Dependencies
- Configuration
- Operations and processes
- Business rules
- Database tables
- SQL catalog
- Service registration
- API reference
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with**could not be confirmed; treat as unknown until verified.
Sources¶
src/SAIF.NetCore.Nhibernate/SAIF.NetCore.NHibernate/SAIF.NetCore.NHibernate/SAIF.NetCore.NHibernate.csprojsrc/SAIF.NetCore.Nhibernate/SAIF.NetCore.NHibernate/SAIF.NetCore.NHibernate/Factories/UnitOfWorkFactory.cssrc/SAIF.NetCore.Nhibernate/SAIF.NetCore.NHibernate/SAIF.NetCore.NHibernate/UnitOfWork.cssrc/SAIF.NetCore.Nhibernate/SAIF.NetCore.NHibernate/SAIF.NetCore.NHibernate/Extensions/IServicesCollectionExtensions.cs