Skip to content

Commit cab8fd4

Browse files
committed
- v10.0.10
1 parent a8faeda commit cab8fd4

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

Shuttle.Core.Data/DatabaseContextCache.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,35 @@ public class DatabaseContextCache : IDatabaseContextCache
77
{
88
public IDatabaseContext Current { get; private set; }
99

10-
public void Use(string name)
10+
public ActiveDatabaseContext Use(string name)
1111
{
12-
Current = DatabaseContexts.Find(candidate => candidate.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
12+
var current = Current;
13+
14+
Current = DatabaseContexts.Find(candidate => candidate.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
1315

1416
if (Current == null)
1517
{
1618
throw new Exception(string.Format(Resources.DatabaseContextNameNotFoundException, name));
1719
}
20+
21+
return new ActiveDatabaseContext(this, current);
1822
}
1923

20-
public void Use(IDatabaseContext context)
24+
public ActiveDatabaseContext Use(IDatabaseContext context)
2125
{
2226
Guard.AgainstNull(context, nameof(context));
2327

28+
var current = Current;
29+
2430
Current = DatabaseContexts.Find(candidate => candidate.Key.Equals(context.Key));
2531

2632
if (Current == null)
2733
{
2834
throw new Exception(string.Format(Resources.DatabaseContextKeyNotFoundException, context.Key));
2935
}
30-
}
36+
37+
return new ActiveDatabaseContext(this, current);
38+
}
3139

3240
public bool Contains(string connectionString)
3341
{
@@ -42,9 +50,10 @@ public void Add(IDatabaseContext context)
4250
}
4351

4452
DatabaseContexts.Add(context);
53+
Use(context);
4554
}
4655

47-
private IDatabaseContext Find(IDatabaseContext context)
56+
private IDatabaseContext Find(IDatabaseContext context)
4857
{
4958
return DatabaseContexts.Find(candidate => candidate.Key.Equals(context.Key));
5059
}
@@ -78,7 +87,7 @@ public IDatabaseContext Get(string connectionString)
7887
return result;
7988
}
8089

81-
public DatabaseContextCollection DatabaseContexts { get; private set; }
90+
public DatabaseContextCollection DatabaseContexts { get; }
8291

8392
public DatabaseContextCache()
8493
{

Shuttle.Core.Data/DatabaseContextFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Configuration;
32
using System.Data;
43
using Shuttle.Core.Contract;
54

Shuttle.Core.Data/IDatabaseContextCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ namespace Shuttle.Core.Data
33
public interface IDatabaseContextCache
44
{
55
IDatabaseContext Current { get; }
6-
void Use(string name);
7-
void Use(IDatabaseContext context);
6+
ActiveDatabaseContext Use(string name);
7+
ActiveDatabaseContext Use(IDatabaseContext context);
88
bool Contains(string connectionString);
99
void Add(IDatabaseContext context);
1010
void Remove(IDatabaseContext context);

Shuttle.Core.Data/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
[assembly: AssemblyTitle(".NET Standard 2.0")]
3434
#endif
3535

36-
[assembly: AssemblyVersion("10.0.9.0")]
36+
[assembly: AssemblyVersion("10.0.10.0")]
3737
[assembly: AssemblyCopyright("Copyright © Eben Roux 2017")]
3838
[assembly: AssemblyProduct("Shuttle.Core.Data")]
3939
[assembly: AssemblyCompany("Shuttle")]
4040
[assembly: AssemblyConfiguration("Release")]
41-
[assembly: AssemblyInformationalVersion("10.0.9")]
41+
[assembly: AssemblyInformationalVersion("10.0.10")]
4242
[assembly: ComVisible(false)]

Shuttle.Core.Data/ThreadStaticDatabaseContextCache.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ public class ThreadStaticDatabaseContextCache : IDatabaseContextCache
66
{
77
[ThreadStatic] private static DatabaseContextCache _cache;
88

9-
public IDatabaseContext Current
10-
{
11-
get { return GuardedCache().Current; }
12-
}
9+
public IDatabaseContext Current => GuardedCache().Current;
1310

14-
public void Use(string name)
11+
public ActiveDatabaseContext Use(string name)
1512
{
16-
GuardedCache().Use(name);
13+
return GuardedCache().Use(name);
1714
}
1815

19-
public void Use(IDatabaseContext context)
16+
public ActiveDatabaseContext Use(IDatabaseContext context)
2017
{
21-
GuardedCache().Use(context);
18+
return GuardedCache().Use(context);
2219
}
2320

2421
public bool Contains(string connectionString)
@@ -29,7 +26,6 @@ public bool Contains(string connectionString)
2926
public void Add(IDatabaseContext context)
3027
{
3128
GuardedCache().Add(context);
32-
GuardedCache().Use(context);
3329
}
3430

3531
public void Remove(IDatabaseContext context)

0 commit comments

Comments
 (0)