Skip to content

Commit

Permalink
signalR fix for .net8
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-tspencer committed Oct 11, 2024
1 parent 692ad46 commit 382b968
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: "6.0.x"
dotnet-version: "8.0.x"

- name: Setup Package Name
id: package_name
Expand Down
11 changes: 4 additions & 7 deletions Cite.Api.Data/CiteContext.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// Copyright 2022 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license, please see LICENSE.md in the project root for license information or contact [email protected] for full terms.

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Cite.Api.Data.Models;
using Cite.Api.Data.Extensions;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;

namespace Cite.Api.Data
{
public class CiteContext : DbContext
{
private DbContextOptions<CiteContext> _options;
// Needed for EventInterceptor
public IServiceProvider ServiceProvider;

public CiteContext(DbContextOptions<CiteContext> options) : base(options) {
_options = options;
}
public CiteContext(DbContextOptions<CiteContext> options) : base(options) { }

public DbSet<ScoringModelEntity> ScoringModels { get; set; }
public DbSet<ScoringCategoryEntity> ScoringCategories { get; set; }
Expand Down Expand Up @@ -50,4 +48,3 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}
}

24 changes: 24 additions & 0 deletions Cite.Api.Data/CiteDbContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information.
using System;
using Microsoft.EntityFrameworkCore;
namespace Cite.Api.Data;
public class CiteContextFactory : IDbContextFactory<CiteContext>
{
private readonly IDbContextFactory<CiteContext> _pooledFactory;
private readonly IServiceProvider _serviceProvider;
public CiteContextFactory(
IDbContextFactory<CiteContext> pooledFactory,
IServiceProvider serviceProvider)
{
_pooledFactory = pooledFactory;
_serviceProvider = serviceProvider;
}
public CiteContext CreateDbContext()
{
var context = _pooledFactory.CreateDbContext();
// Inject the current scope's ServiceProvider
context.ServiceProvider = _serviceProvider;
return context;
}
}
49 changes: 49 additions & 0 deletions Cite.Api.Data/Entry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace Cite.Api.Data;
public class Entry
{
public object Entity { get; set; }
public EntityState State { get; set; }
public IEnumerable<PropertyEntry> Properties { get; set; }
private Dictionary<string, bool> IsPropertyModified { get; set; } = new();
public Entry(EntityEntry entry, Entry oldEntry = null)
{
Entity = entry.Entity;
State = entry.State;
Properties = entry.Properties;
ProcessOldEntry(oldEntry);
foreach (var prop in Properties)
{
IsPropertyModified[prop.Metadata.Name] = prop.IsModified;
}
}
private void ProcessOldEntry(Entry oldEntry)
{
if (oldEntry == null) return;
if (oldEntry.State != EntityState.Unchanged && oldEntry.State != EntityState.Detached)
{
State = oldEntry.State;
}
var modifiedProperties = oldEntry.GetModifiedProperties();
foreach (var property in Properties)
{
if (modifiedProperties.Contains(property.Metadata.Name))
{
property.IsModified = true;
}
}
}
public string[] GetModifiedProperties()
{
return IsPropertyModified
.Where(x => x.Value)
.Select(x => x.Key)
.ToArray();
}
}
158 changes: 0 additions & 158 deletions Cite.Api/Infrastructure/EventHandlers/EntityTransactionInterceptor.cs

This file was deleted.

Loading

0 comments on commit 382b968

Please sign in to comment.