Dapper. Repository. UnitOfWork
See the version list below for details.
NuGet\Install-Package Smooth.IoC.Dapper.Repository.UnitOfWork -Version 0.1.0-CI00059
dotnet add package Smooth.IoC.Dapper.Repository.UnitOfWork --version 0.1.0-CI00059
<PackageReference Include="Smooth.IoC.Dapper.Repository.UnitOfWork" Version="0.1.0-CI00059" />
paket add Smooth.IoC.Dapper.Repository.UnitOfWork --version 0.1.0-CI00059
#r "nuget: Smooth.IoC.Dapper.Repository.UnitOfWork, 0.1.0-CI00059"
// Install Smooth.IoC.Dapper.Repository.UnitOfWork as a Cake Addin #addin nuget:?package=Smooth.IoC.Dapper.Repository.UnitOfWork&version=0.1.0-CI00059&prerelease // Install Smooth.IoC.Dapper.Repository.UnitOfWork as a Cake Tool #tool nuget:?package=Smooth.IoC.Dapper.Repository.UnitOfWork&version=0.1.0-CI00059&prerelease
I made this project to fix the contradictory concepts behind the Repository and UnitOfWork patterns together with using inversition of control / dependancy injection. Also i wanted to make the resolving of sessions (IDbConnection) and UnitOFWork's (IDbTransaction) automatically connection / begin transaction on creation, and disconnect/commit on disposal.
Also i wanted the usage of the session and uow to become nice and simple.
This should cover 97% of your needs. But i have also insured the the Session and UoW types extend the ADO base interfaces, so you can basically do anything you like with the session / uow, because they are IDbConnection and IDbTransaction.
I have tried to insure it is as bare bones as possible. Only adding the system libraries needed and Dapper + Dapper.FASTCrud. The IoC of your choice is not included in the package,
but i have made example registrations for the "majors" look on the project site.
*So far there are examples of Autofact, Castle.Windsor, Ninject, Simpleinjector, StructureMap, and Unity.*
Included interfaces with abstractions:
1. **IDbFactory** is a simple interface that you register with your IoC. It can create/spwan ISession's and IUntOfWork's. But primary used in code to spawn sessions.
2. **ISession<TDatabase>** (and Session<TDatabase> abstraction): Extends IDbConnection. You use it to extend your Database connection / Session type. Yours session classes
and interfaces require a connection string. So If you have multiple database connections, you need 1 ISession and Session extended Interface and class per database. When the session is
created by the factory it connects to the database, when it disposes it discontects and disposes. For Castle Windsor it also untracks the object. You can use the session for any IDbConnection or dapper (or extension) framework you like, as ISession extends IDbConnection ;-).
3. **IUnitOfWork** (and UnitOfWork): Extends IDbTransaction. You don't need to extend anything with this. When you have created a session in you code, you can create a uow from the session. Then the session is created by the factory it begins a transaction (isolation i a parameter), when it disposes it commits (roleback on exception) and disposes. For Castle Windsor it also untracks the object. You can use the transaction for any IDbTransaction work you like as
IUnitOfWork extends IDbTransaction ;-).
4. **IRepository<TSession, TEntity, TPk>** (Repository<TSession, TEntity, TPk> abstraction): Is a default repository that you extend with your own repository for each of
the entities you want a repository for. There as some built in methods for GetAll, Get, and SaveOrUpdate. You can add the methods you need for your entity using any IDbConnection framework.
have used [dapper-dot-net](https://github.com/StackExchange/dapper-dot-net) and [dapper.FastCRUD](https://github.com/MoonStorm/Dapper.FastCRUD) for the quering.
5. **IEntity<TPk>**: An interface for your Entities so FastCRUD GetKey works in Repositories. To use this your table / entity should always have and Id column as Pk in
what every type you like (its a generic :-).
6. **IRepositoryBase** (and RepositoryBase<TEntity> abstraction): This is a vanilla base repository, you can use it if you do not want to use Dapper or Dapper.FastCRUD
and/or IEntity interface. It includes an protected method to set the dialect which you will need to do, if you want to use FastCRUD but without the IEntity interface.
|.NET||net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows|
|.NET Core||netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1|
|.NET Standard||netstandard1.6 netstandard2.0 netstandard2.1|
|.NET Framework||net452 net46 net461 net462 net463 net47 net471 net472 net48|
|Tizen||tizen30 tizen40 tizen60|
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.