Skip to content

Commit

Permalink
Fixed issue with Logger in Dbcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
vivet committed Oct 5, 2024
1 parent a229550 commit ef5c04a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
25 changes: 10 additions & 15 deletions Nano.Data/BaseDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public abstract class BaseDbContext<TIdentity> : IdentityDbContext<IdentityUser<
/// </summary>
public DataOptions Options { get; }

/// <summary>
/// Logger.
/// </summary>
public ILogger Logger { get; }

/// <summary>
/// Auto Save.
/// </summary>
Expand All @@ -72,11 +67,9 @@ protected BaseDbContext(DbContextOptions contextOptions, DataOptions dataOptions
{
this.Options = dataOptions ?? throw new ArgumentNullException(nameof(dataOptions));

this.Logger = this.GetService<ILogger>();

this.SavingChanges += (_, _) => this.SetPendingEntityEvents();
this.SavingChanges += (_, _) => this.SaveSoftDeletion();
this.SavedChanges += async (_, _) => await this.ExecuteEntityEvents();
this.SavedChanges += async (_, _) => await this.PublishEntityEvents();

// ReSharper disable VirtualMemberCallInConstructor
this.ChangeTracker.LazyLoadingEnabled = this.Options.UseLazyLoading;
Expand Down Expand Up @@ -288,7 +281,9 @@ internal virtual Task EnsureMigratedAsync(CancellationToken cancellationToken =
if (this.Options.ConnectionString == null)
return Task.CompletedTask;

this.Logger
var logger = this.GetService<ILogger>();

logger
.LogInformation("Applying Migrations at start-up.");

return this.Database
Expand Down Expand Up @@ -408,15 +403,15 @@ private void SaveAudit(object entity, object tracked = null, EntityEntry owner =

try
{
var entry = owner == null
? this.Entry(entity)
: propertName == null
? this.Entry(entity)
var entry = owner == null
? this.Entry(entity)
: propertName == null
? this.Entry(entity)
: owner.Reference(propertName).TargetEntry;

if (entry == null)
{
throw new NullReferenceException(nameof(entry));
return;
}

var properties = entity
Expand Down Expand Up @@ -648,7 +643,7 @@ private object GetNestedPropertyValue(PropertyInfo property, string propertyName
return propertyNested
.GetValue(parent);
}
private async Task ExecuteEntityEvents()
private async Task PublishEntityEvents()
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion NanoCore.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>NanoCore</id>
<version>8.1.27</version>
<version>8.1.28</version>
<title>Nano Core</title>
<summary>Rapidly built and deploy rich .NET 8.0 applications. Configuration, Security, Logging, Data, Hosting, Docs, Localization, Versioning, Api, Error-Handling, and much more.</summary>
<description>The project is inspired by years of tedious repetitions, continuously re-writing similar code-snippets and libraries, to handle common functionality, not related to the business domain, such as logging, data persistence, message queuing, documentation, validation and similar.</description>
Expand Down

0 comments on commit ef5c04a

Please sign in to comment.