ISessionStrategy¶
ISessionStrategy is the seam contract abstracting stateful (ISession) vs. stateless (IStatelessSession) NHibernate session semantics behind a single interface. RepositoryBase<TEntity> and NHibernateUnitOfWork code against this interface only, so the same repository/unit-of-work code works unchanged whether it is backed by StatefulSessionStrategy or StatelessSessionStrategy (both internal, not part of the public surface).
Purpose¶
- Defines the common CRUD/query/transaction operations (
Clear,BeginTransaction,Transaction,CreateSqlQuery,Delete,Add,Update,Query<TEntity>,GetNamedQuery,Get<TEntity>,Load<TEntity>,Dispose) that both session kinds must support. - Is the type through which the Repository CRUD and query operations (stateful vs stateless divergence) operation is expressed: implementations differ chiefly in
Update(no-op vs. explicit write, see BR-003) andLoad(lazy proxy vs. eager fetch).
Context¶
- Namespace:
SAIF.Data.NHibernate.Interfaces - Assembly/package:
SAIF.Framework.Data.NHibernate
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| Clear | void Clear() |
Clears the session's first-level cache/tracked state. Called by NHibernateUnitOfWork.Begin() before starting a new transaction. |
| BeginTransaction | ITransaction BeginTransaction(IsolationLevel isolationLevel) |
Starts a new transaction at the given isolation level. Called by NHibernateUnitOfWork.Begin() with IsolationLevel.ReadCommitted. |
| Transaction | ITransaction Transaction() |
Returns the current (possibly inactive) transaction, used by NHibernateUnitOfWork.Commit()/Rollback() to check IsActive/WasCommitted/WasRolledBack. |
| CreateSqlQuery | ISQLQuery CreateSqlQuery(string sql) |
Direct SQL escape hatch used by ImageRepositoryExtensions for Oracle sequence NEXTVAL queries; bypasses entity mapping entirely. |
| Delete | void Delete(object entity) |
Deletes entity from the session in both stateful and stateless strategies. |
| Add | void Add(object entity) |
Stateful: ISession.SaveOrUpdate(entity). Stateless: IStatelessSession.Insert(entity). |
| Update | void Update(object entity) |
Stateful: no-op (relies on dirty-checking flush at commit). Stateless: explicit IStatelessSession.Update(entity). See BR-003. |
| Query<TEntity> | IQueryable<TEntity> Query<TEntity>() |
Returns Session.Query<TEntity>() (LINQ to NHibernate) in both strategies. |
| GetNamedQuery | IQuery GetNamedQuery(string name) |
Retrieves a named HQL/SQL query configured in the mapping set. |
| Get<TEntity> | TEntity Get<TEntity>(object id) |
Stateful: ISession.Get<TEntity>(id). Stateless: IStatelessSession.Get<TEntity>(id). |
| Load<TEntity> | TEntity Load<TEntity>(object id) |
Stateful: ISession.Load<TEntity>(id) (lazy proxy). Stateless: delegates to Get<TEntity>(id) — no distinct lazy path. |
| Dispose | void Dispose() |
Disposes the underlying ISession/IStatelessSession. |
Behavioral notes¶
- The two internal implementations,
StatefulSessionStrategyandStatelessSessionStrategy, are the sole source of the stateful/stateless divergence documented throughout this library's business rules and operations; consumers ofISessionStrategyitself never see which concrete implementation they hold.
Constraints and usage notes¶
- This interface is implemented only by the two
internalclasses inSessions/; external consumers cannot supply a custom implementation without also having those types beinternal-visible (i.e., in practice, only code within this assembly can implementISessionStrategy).
Sources¶
Interfaces/ISessionStrategy.csSessions/StatefulSessionStrategy.csSessions/StatelessSessionStrategy.cs