Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced DateTimeService with System.TimeProvider #884

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Application/Common/Interfaces/IDateTime.cs

This file was deleted.

4 changes: 1 addition & 3 deletions src/Infrastructure/ConfigureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using CleanArchitecture.Infrastructure.Identity;
using CleanArchitecture.Infrastructure.Persistence;
using CleanArchitecture.Infrastructure.Persistence.Interceptors;
using CleanArchitecture.Infrastructure.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -36,8 +35,7 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti
.AddDefaultIdentity<ApplicationUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();

services.AddTransient<IDateTime, DateTimeService>();

services.AddTransient<IIdentityService, IdentityService>();
services.AddTransient<ICsvFileBuilder, CsvFileBuilder>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace CleanArchitecture.Infrastructure.Persistence.Interceptors;
public class AuditableEntitySaveChangesInterceptor : SaveChangesInterceptor
{
private readonly IUser _user;
private readonly IDateTime _dateTime;
private readonly TimeProvider _timeProvider;

public AuditableEntitySaveChangesInterceptor(
IUser user,
IDateTime dateTime)
TimeProvider timeProvider)
{
_user = user;
_dateTime = dateTime;
_timeProvider = timeProvider;
}

public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
Expand All @@ -42,13 +42,13 @@ public void UpdateEntities(DbContext? context)
if (entry.State == EntityState.Added)
{
entry.Entity.CreatedBy = _user.Id;
entry.Entity.Created = _dateTime.Now;
entry.Entity.Created = _timeProvider.GetLocalNow().DateTime;
}

if (entry.State == EntityState.Added || entry.State == EntityState.Modified || entry.HasChangedOwnedEntities())
{
entry.Entity.LastModifiedBy = _user.Id;
entry.Entity.LastModified = _dateTime.Now;
entry.Entity.LastModified = _timeProvider.GetLocalNow().DateTime;
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/Infrastructure/Services/DateTimeService.cs

This file was deleted.