Skip to content

Commit dd41aa3

Browse files
committed
Use new type "Lock" instead of object in .NET 9
1 parent f34233b commit dd41aa3

File tree

11 files changed

+35
-16
lines changed

11 files changed

+35
-16
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<RepositoryUrl>https://[email protected]/pawelgerr/Thinktecture.EntityFrameworkCore/_git/Thinktecture.EntityFrameworkCore</RepositoryUrl>
1313
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1414
<RootNamespace>Thinktecture</RootNamespace>
15-
<TargetFramework>net8.0</TargetFramework>
15+
<TargetFrameworks>net8.0;net9.0;</TargetFrameworks>
1616
<LangVersion>13.0</LangVersion>
1717
<Nullable>enable</Nullable>
1818
<NoWarn>$(NoWarn);CA1303;MSB3884;</NoWarn>

src/Thinktecture.EntityFrameworkCore.BulkOperations/EntityFrameworkCore/TempTables/NameSuffixing/TempTableSuffixCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace Thinktecture.EntityFrameworkCore.TempTables.NameSuffixing;
55

66
internal class TempTableSuffixCache
77
{
8-
private readonly object _lock;
8+
private readonly Lock _lock;
99
private readonly Dictionary<DbConnection, CachedTempTableSuffixes> _globalCache;
1010

1111
public TempTableSuffixCache()
1212
{
13-
_lock = new object();
13+
_lock = new Lock();
1414
_globalCache = new Dictionary<DbConnection, CachedTempTableSuffixes>();
1515
}
1616

src/Thinktecture.EntityFrameworkCore.BulkOperations/EntityFrameworkCore/TempTables/NameSuffixing/TempTableSuffixLeasing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Thinktecture.EntityFrameworkCore.TempTables.NameSuffixing;
66

77
internal class TempTableSuffixLeasing : IDisposable
88
{
9-
private readonly object _lock;
9+
private readonly Lock _lock;
1010
private readonly TempTableSuffixCache _cache;
1111
private readonly ICurrentDbContext _currentDbContext;
1212
private DbConnection? _connection;
@@ -20,7 +20,7 @@ public TempTableSuffixLeasing(
2020
{
2121
_cache = cache ?? throw new ArgumentNullException(nameof(cache));
2222
_currentDbContext = currentDbContext ?? throw new ArgumentNullException(nameof(currentDbContext));
23-
_lock = new object();
23+
_lock = new Lock();
2424

2525
// don't fetch the connection and suffix lookup immediately but on first use only
2626
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using Lock =
2+
#if NET9_0_OR_GREATER
3+
System.Threading.Lock;
4+
#else
5+
System.Object;
6+
#endif

src/Thinktecture.EntityFrameworkCore.SqlServer.Testing/EntityFrameworkCore/Testing/SqlServerTestDbContextProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ namespace Thinktecture.EntityFrameworkCore.Testing;
1313
/// </summary>
1414
public abstract class SqlServerTestDbContextProvider
1515
{
16-
private static readonly object _sharedLock = new();
16+
private static readonly Lock _sharedLock = new();
1717

1818
/// <summary>
1919
/// Provides a lock object for database-wide operations like creation of tables.
2020
/// </summary>
2121
/// <param name="ctx">Current database context.</param>
2222
/// <returns>A lock object.</returns>
23-
protected virtual object GetSharedLock(DbContext ctx)
23+
protected virtual Lock GetSharedLock(DbContext ctx)
2424
{
2525
return _sharedLock;
2626
}
@@ -33,7 +33,7 @@ protected virtual object GetSharedLock(DbContext ctx)
3333
public class SqlServerTestDbContextProvider<T> : SqlServerTestDbContextProvider, ITestDbContextProvider<T>
3434
where T : DbContext
3535
{
36-
private readonly object _instanceWideLock;
36+
private readonly Lock _instanceWideLock;
3737
private readonly ITestIsolationOptions _isolationOptions;
3838
private readonly DbContextOptions<T> _masterDbContextOptions;
3939
private readonly DbContextOptions<T> _dbContextOptions;
@@ -93,7 +93,7 @@ protected internal SqlServerTestDbContextProvider(SqlServerTestDbContextProvider
9393
{
9494
ArgumentNullException.ThrowIfNull(options);
9595

96-
_instanceWideLock = new object();
96+
_instanceWideLock = new Lock();
9797
Schema = options.Schema;
9898
_sharedTablesIsolationLevel = ValidateIsolationLevel(options.SharedTablesIsolationLevel);
9999
_isolationOptions = options.IsolationOptions;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using Lock =
2+
#if NET9_0_OR_GREATER
3+
System.Threading.Lock;
4+
#else
5+
System.Object;
6+
#endif

src/Thinktecture.EntityFrameworkCore.Sqlite.Testing/EntityFrameworkCore/Testing/SqliteTestDbContextProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Thinktecture.EntityFrameworkCore.Testing;
1212
public class SqliteTestDbContextProvider<T> : ITestDbContextProvider<T>
1313
where T : DbContext
1414
{
15-
private readonly object _lock = new();
15+
private readonly Lock _lock = new();
1616

1717
private readonly DbContextOptions<T> _masterDbContextOptions;
1818
private readonly DbContextOptions<T> _dbContextOptions;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using Lock =
2+
#if NET9_0_OR_GREATER
3+
System.Threading.Lock;
4+
#else
5+
System.Object;
6+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using Lock =
2+
#if NET9_0_OR_GREATER
3+
System.Threading.Lock;
4+
#else
5+
System.Object;
6+
#endif

src/Thinktecture.EntityFrameworkCore.Testing/Logging/SubLoggerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Thinktecture.Logging;
55
internal class SubLoggerFactory : ILoggerProvider
66
{
77
private readonly Dictionary<string, SubLogger> _loggers = new(StringComparer.Ordinal);
8-
private readonly object _sync = new();
8+
private readonly Lock _sync = new();
99

1010
private readonly ILoggerFactory _loggerFactory;
1111

0 commit comments

Comments
 (0)