EFCoreHooks 0.1.0
dotnet add package EFCoreHooks --version 0.1.0
NuGet\Install-Package EFCoreHooks -Version 0.1.0
<PackageReference Include="EFCoreHooks" Version="0.1.0" />
<PackageVersion Include="EFCoreHooks" Version="0.1.0" />
<PackageReference Include="EFCoreHooks" />
paket add EFCoreHooks --version 0.1.0
#r "nuget: EFCoreHooks, 0.1.0"
#:package EFCoreHooks@0.1.0
#addin nuget:?package=EFCoreHooks&version=0.1.0
#tool nuget:?package=EFCoreHooks&version=0.1.0
EFCoreHooks
This project provides a simple, attribute-based hooking system for all projects using all versions of Microsoft's Entity Framework Core 2.1 and above.
Installation
Make sure you have Nuget installed, the run
PM> Install-Package EFCoreHooks
Usage
First you must edit your ConfigureServices(IServiceCollection) so the hooking system can have access
to the Dependency Injection Container
using EFCoreHooks;
/* ... */
public void ConfigureServices(IServiceColleciton services) {
/* ... */
services.ConfigureDbHooks();
/* ... */
}
In most cases the only other thing you need to do is to have any dbcontext that you want to have hooks
extends from HookedDbContext or HookedIdentityDbContext. Both classes are designed to be drop-in
replacements for DbContext and IdentityDbContext respectively.
In cases where you need a base class other than DbContext or IdentityDbContext, you can use the
extension methods directly by implementing IHookedDbContext, and overriding the SaveChanges and
SaveChagnesAsync methods to call the extension methods instead of the base class.
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
return this.HookedSaveChanges(acceptAllChangesOnSuccess);
}
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,
CancellationToken cancellationToken = default(CancellationToken))
{
return this.HookedSaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
Implementing the IHookedDbContext interface is quite simple:
public class HookedDbContext : DbContext, IHookedDbContext
{
public HookedDbContext(DbContextOptions options, HookManagerContainer hooks) : base(options)
{
Hooks = hooks;
Hooks.InitializeForAll(this);
}
public HookManagerContainer Hooks { get; }
public int SaveChangesBase(bool acceptAllChanges)
{
// Mirror the base classes saved changes so the extension methods can access them
return base.SaveChanges(acceptAllChanges);
}
public Task<int> SaveChangesBaseAsync(bool acceptAllChanges,
CancellationToken cancellationToken = default(CancellationToken))
{
// Mirror the base classes saved changes so the extension methods can access them
return base.SaveChangesAsync(acceptAllChanges, cancellationToken);
}
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
// Run the extension method instead of the base class's method
return this.HookedSaveChanges(acceptAllChangesOnSuccess);
}
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,
CancellationToken cancellationToken = default(CancellationToken))
{
// Run the extension method instead of the base class's method
return this.HookedSaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 2.1.0)
- Microsoft.EntityFrameworkCore (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 1,025 | 7/10/2019 |
Initial Release