![]() |
VOOZH | about |
dotnet add package Simplify.Repository.FluentNHibernate --version 1.7.4
NuGet\Install-Package Simplify.Repository.FluentNHibernate -Version 1.7.4
<PackageReference Include="Simplify.Repository.FluentNHibernate" Version="1.7.4" />
<PackageVersion Include="Simplify.Repository.FluentNHibernate" Version="1.7.4" />Directory.Packages.props
<PackageReference Include="Simplify.Repository.FluentNHibernate" />Project file
paket add Simplify.Repository.FluentNHibernate --version 1.7.4
#r "nuget: Simplify.Repository.FluentNHibernate, 1.7.4"
#:package Simplify.Repository.FluentNHibernate@1.7.4
#addin nuget:?package=Simplify.Repository.FluentNHibernate&version=1.7.4Install as a Cake Addin
#tool nuget:?package=Simplify.Repository.FluentNHibernate&version=1.7.4Install as a Cake Tool
Provides Repository and Unit of Work abstractions, plus ready-made implementations for Entity Framework Core and FluentNHibernate. The same abstraction layer (Simplify.Repository) works with either ORM, so application code depends only on the interfaces.
The family consists of three packages:
| Package | Purpose |
|---|---|
| Simplify.Repository | Core abstractions: entity markers, IGenericRepository<T>, unit of work interfaces, and the TransactGenericRepository<T> transaction wrapper. |
| Simplify.Repository.EntityFramework | Implementations over EF Core DbContext. |
| Simplify.Repository.FluentNHibernate | Implementations over NHibernate ISession / IStatelessSession. |
Simplify.Repository)Implement (or derive from a base class that implements) one of these:
| Interface | Key |
|---|---|
IIdentityObject |
int ID { get; set; } |
ILongIdentityObject |
long ID { get; } |
IStringIdentityObject |
string? ID { get; set; } |
INamedObject : IIdentityObject |
adds string? Name { get; set; } |
ILongNamedObject : ILongIdentityObject |
adds string? Name { get; set; } |
IGenericRepository<T> where T : classRead methods (each has an ...Async counterpart returning Task<...>):
T GetSingleByID(object id);
T GetSingleByQuery(Expression<Func<T, bool>> query);
T GetFirstByQuery(Expression<Func<T, bool>> query);
IList<T> GetMultiple(Expression<Func<T, bool>>? query = null, Func<IQueryable<T>, IQueryable<T>>? customProcessing = null);
IList<T> GetPaged(int pageIndex, int itemsPerPage, Expression<Func<T, bool>>? query = null, Func<IQueryable<T>, IQueryable<T>>? customProcessing = null);
int GetCount(Expression<Func<T, bool>>? query = null);
long GetLongCount(Expression<Func<T, bool>>? query = null);
Write methods (with ...Async counterparts):
object Add(T entity); // returns the generated identifier
void Update(T entity);
void Delete(T entity);
public interface IUnitOfWork : IDisposable { }
public interface ITransactUnitOfWork : IUnitOfWork
{
bool IsTransactionActive { get; }
void BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted);
void Commit();
Task CommitAsync();
void Rollback();
Task RollbackAsync();
}
TransactGenericRepository<T>A wrapper (IGenericRepository<T>) that automatically begins and commits/rolls back a transaction around each operation when no transaction is already active. It is what the DI registration extensions wire up for you.
public TransactGenericRepository(IGenericRepository<T> baseRepository,
ITransactUnitOfWork unitOfWork,
IsolationLevel isolationLevel = IsolationLevel.ReadCommitted);
Simplify.Repository.FluentNHibernate)Provides:
IdentityObject, LongIdentityObject, NamedObject, LongNamedObject, and StringIdentityObject (all with virtual properties).GenericRepository<T>(ISession session) — uses a stateful NHibernate ISession.StatelessGenericRepository<T>(IStatelessSession session) — uses a lighter IStatelessSession.Unit of work implementations: UnitOfWork(ISessionFactory), StatelessUnitOfWork(ISessionFactory), TransactUnitOfWork(ISessionFactory), TransactStatelessUnitOfWork(ISessionFactory).
Mapping base classes (FluentNHibernate ClassMap<T>): IdentityObjectMap<T>, NamedObjectMap<T>, LongIdentityObjectMap<T>, LongNamedObjectMap<T>, StringIdentityObjectMap<T>.
using Simplify.Repository.FluentNHibernate;
using Simplify.Repository.FluentNHibernate.Mappings;
public class User : NamedObject
{
public virtual string? Email { get; set; }
}
public class UserMap : NamedObjectMap<User> // base maps Id(x => x.ID) and Map(x => x.Name).Not.Nullable()
{
public UserMap()
{
Map(x => x.Email).Nullable();
}
}
using Simplify.DI;
using Simplify.Repository;
using Simplify.Repository.FluentNHibernate;
using NHibernate;
DIContainer.Current
.Register<TransactUnitOfWork>(r => new TransactUnitOfWork(r.Resolve<ISessionFactory>()))
.Register<ITransactUnitOfWork>(r => r.Resolve<TransactUnitOfWork>())
.RegisterTransactRepository<User, ITransactUnitOfWork>();
// For stateless sessions, use the stateless overloads instead:
// .RegisterStatelessTransactRepository<User, ITransactUnitOfWork>();
The FluentNHibernate package provides both RegisterTransactRepository<...> and RegisterStatelessTransactRepository<...> (each with a two- and three-type-parameter overload).
Simplify.Repository.EntityFramework)Provides:
IdentityObject, LongIdentityObject, NamedObject, LongNamedObject (all with virtual properties).GenericRepository<T>(DbContext session) — IGenericRepository<T> over a DbContext.UnitOfWork<T>(DbContext context) where T : DbContext — exposes Context.TransactUnitOfWork<T>(DbContext context) where T : DbContext — ITransactUnitOfWork.Microsoft.EntityFrameworkCore IEntityTypeConfiguration<T>): IdentityObjectMap<T>, NamedObjectMap<T>, LongIdentityObjectMap<T>, LongNamedObjectMap<T>.using Simplify.Repository.EntityFramework;
using Simplify.Repository.EntityFramework.Mappings;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class User : NamedObject
{
public virtual string? Email { get; set; }
}
public class UserMap : NamedObjectMap<User> // ID + required Name are configured by the base class
{
protected override void ConfigureEntity(EntityTypeBuilder<User> builder)
{
builder.Property(x => x.Email).HasMaxLength(255);
}
}
Apply the mapping in your DbContext.OnModelCreating:
protected override void OnModelCreating(ModelBuilder modelBuilder) =>
modelBuilder.ApplyConfiguration(new UserMap());
RegisterTransactRepository<T, TUnitOfWork> registers GenericRepository<T> and exposes IGenericRepository<T> as a transaction-wrapped repository:
using System.Data;
using Simplify.DI;
using Simplify.Repository;
using Simplify.Repository.EntityFramework;
DIContainer.Current
// your DbContext and a unit of work implementing ITransactUnitOfWork must be registered first
.Register<ITransactUnitOfWork>(r => new TransactUnitOfWork<AppDbContext>(r.Resolve<AppDbContext>()))
.RegisterTransactRepository<User, ITransactUnitOfWork>();
There is also a three-type-parameter overload that builds the repository from a concrete unit of work's Context:
RegisterTransactRepository<User, ITransactUnitOfWork, MyUnitOfWorkImpl>(IsolationLevel.ReadCommitted);
// where MyUnitOfWorkImpl : UnitOfWork<DbContext>
Note: the stateless-repository registration overloads are not yet implemented for the EntityFramework package.
Once registered, inject IGenericRepository<T> (transaction handling is automatic via the wrapper):
public class UserService(IGenericRepository<User> users)
{
public Task<User> GetAsync(int id) => users.GetSingleByIDAsync(id);
public Task<IList<User>> SearchAsync(string namePart) =>
users.GetMultipleAsync(u => u.Name != null && u.Name.Contains(namePart));
public async Task<object> CreateAsync(string name, string email) =>
await users.AddAsync(new User { Name = name, Email = email });
}
For explicit transaction control, resolve and use an ITransactUnitOfWork directly:
unitOfWork.BeginTransaction();
var id = await repository.AddAsync(user);
await unitOfWork.CommitAsync();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 is compatible. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.7.4 | 54 | 6/25/2026 |
| 1.7.2 | 398 | 10/10/2025 |
| 1.7.1 | 491 | 12/2/2024 |
| 1.7.0 | 1,471 | 1/14/2024 |
| 1.6.0 | 487 | 8/7/2023 |
| 1.5.1 | 480 | 4/17/2023 |
| 1.5.0 | 1,100 | 10/28/2021 |
| 1.4.0 | 1,271 | 2/28/2021 |
| 1.3.0 | 754 | 2/26/2021 |
| 1.3.0-pre03 | 508 | 2/26/2021 |
| 1.3.0-pre02 | 511 | 2/25/2021 |
| 1.3.0-pre01 | 575 | 12/23/2020 |
| 1.2.5 | 949 | 1/22/2021 |
| 1.2.4 | 1,074 | 11/19/2020 |
| 1.2.3 | 948 | 10/7/2020 |
| 1.2.2 | 1,211 | 4/29/2020 |
| 1.2.1 | 1,137 | 3/4/2020 |
| 1.2.0 | 1,157 | 11/8/2019 |
| 1.1.0 | 993 | 10/30/2019 |
| 1.0.2 | 1,306 | 6/24/2019 |