ZUnitOfWork 1.1.4
dotnet add package ZUnitOfWork --version 1.1.4
NuGet\Install-Package ZUnitOfWork -Version 1.1.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZUnitOfWork" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZUnitOfWork" Version="1.1.4" />
<PackageReference Include="ZUnitOfWork" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZUnitOfWork --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ZUnitOfWork, 1.1.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZUnitOfWork@1.1.4
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZUnitOfWork&version=1.1.4
#tool nuget:?package=ZUnitOfWork&version=1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ZUnitOfWork
What is ZUnitOfWork
ZUnitOfWork is a extension to implement UnitOfWork and Generic Repository patterns.
I used for
Example for implement ZUnitOfWork:
/// Appsettings.json.
{
"ConnectionStrings": {
"StoreDb": "Server=localhost\\SQLEXPRESS;Database=Store;Trusted_Connection=True;MultipleActiveResultSets=true;Trust Server Certificate=true"
}
}
/// Class for mapping toys db.
namespace Store;
public class Toys
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
/// Own DbContext
namespace Store;
using Microsoft.EntityFrameworkCore;
using ZUnitOfWork;
public class StoreContext(DbContextOptions<StoreContext> dbContextOptions)
: ZDbContext(dbContextOptions)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Toys>(e =>
{
e.ToTable("Toys");
e.HasKey("Id");
e.Property(p => p.Name)
.HasMaxLength(300)
.IsRequired();
});
}
}
/// Function into startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Dependency injection for Toys.
services.AddScoped<IUnitOfWork<Toys>, UnitOfWork<Toys>>();
/// DbContext
// ZDbContext is internal dbcontext for able to implement own DbContext.
services.AddScoped<ZDbContext, StoreContext>();
services.AddDbContext<StoreContext>(option =>
option.UseSqlServer(configuration["ConnectionStrings:StoreDb"]));
}
/// class to implement IUnitOfWork
public class Services(IUnitOfWork<Toys> unitOfWork)
{
private readonly IUnitOfWork<Toys> _unitOfWork = unitOfWork;
// same example to get(all), find (first), any(bool)
public async Task<Toys> GetToy(string toyName, CancellationToken cancellationToken)
{
return await _unitOfWork.Services1.FindAsync(x => x.Name == toyName
, cancellationToken)
}
// same example to add, update or delete
public Task<bool> AddToy(string toyName, CancellationToken cancellationToken)
{
try
{
await _unitOfWork.BeginTransactionAsync(cancellationToken);
var toy = new Toys
{
Name = toyName;
};
var entityResult = await _unitOfWork.Services1.AddAsync(toy, cancellationToken);
if (!entityResult.Status)
$"Toy '{toyName}' cannot been register, try again.".ThrowException(409);
await _unitOfWork.EndTransactionAsync(cancellationToken);
return entityResult.Status.ZOk();
}
catch
{
await _unitOfWork.RollbackTransactionAsync(cancellationToken);
throw;
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.7)
- Microsoft.EntityFrameworkCore.Abstractions (>= 9.0.7)
- Microsoft.EntityFrameworkCore.Proxies (>= 9.0.7)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.7)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.