Skip to content

Commit

Permalink
- v10.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
eben-roux committed Dec 3, 2018
1 parent a8faeda commit cab8fd4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
21 changes: 15 additions & 6 deletions Shuttle.Core.Data/DatabaseContextCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,35 @@ public class DatabaseContextCache : IDatabaseContextCache
{
public IDatabaseContext Current { get; private set; }

public void Use(string name)
public ActiveDatabaseContext Use(string name)
{
Current = DatabaseContexts.Find(candidate => candidate.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
var current = Current;

Current = DatabaseContexts.Find(candidate => candidate.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

if (Current == null)
{
throw new Exception(string.Format(Resources.DatabaseContextNameNotFoundException, name));
}

return new ActiveDatabaseContext(this, current);
}

public void Use(IDatabaseContext context)
public ActiveDatabaseContext Use(IDatabaseContext context)
{
Guard.AgainstNull(context, nameof(context));

var current = Current;

Current = DatabaseContexts.Find(candidate => candidate.Key.Equals(context.Key));

if (Current == null)
{
throw new Exception(string.Format(Resources.DatabaseContextKeyNotFoundException, context.Key));
}
}

return new ActiveDatabaseContext(this, current);
}

public bool Contains(string connectionString)
{
Expand All @@ -42,9 +50,10 @@ public void Add(IDatabaseContext context)
}

DatabaseContexts.Add(context);
Use(context);
}

private IDatabaseContext Find(IDatabaseContext context)
private IDatabaseContext Find(IDatabaseContext context)
{
return DatabaseContexts.Find(candidate => candidate.Key.Equals(context.Key));
}
Expand Down Expand Up @@ -78,7 +87,7 @@ public IDatabaseContext Get(string connectionString)
return result;
}

public DatabaseContextCollection DatabaseContexts { get; private set; }
public DatabaseContextCollection DatabaseContexts { get; }

public DatabaseContextCache()
{
Expand Down
1 change: 0 additions & 1 deletion Shuttle.Core.Data/DatabaseContextFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Configuration;
using System.Data;
using Shuttle.Core.Contract;

Expand Down
4 changes: 2 additions & 2 deletions Shuttle.Core.Data/IDatabaseContextCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Shuttle.Core.Data
public interface IDatabaseContextCache
{
IDatabaseContext Current { get; }
void Use(string name);
void Use(IDatabaseContext context);
ActiveDatabaseContext Use(string name);
ActiveDatabaseContext Use(IDatabaseContext context);
bool Contains(string connectionString);
void Add(IDatabaseContext context);
void Remove(IDatabaseContext context);
Expand Down
4 changes: 2 additions & 2 deletions Shuttle.Core.Data/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
[assembly: AssemblyTitle(".NET Standard 2.0")]
#endif

[assembly: AssemblyVersion("10.0.9.0")]
[assembly: AssemblyVersion("10.0.10.0")]
[assembly: AssemblyCopyright("Copyright © Eben Roux 2017")]
[assembly: AssemblyProduct("Shuttle.Core.Data")]
[assembly: AssemblyCompany("Shuttle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyInformationalVersion("10.0.9")]
[assembly: AssemblyInformationalVersion("10.0.10")]
[assembly: ComVisible(false)]
14 changes: 5 additions & 9 deletions Shuttle.Core.Data/ThreadStaticDatabaseContextCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ public class ThreadStaticDatabaseContextCache : IDatabaseContextCache
{
[ThreadStatic] private static DatabaseContextCache _cache;

public IDatabaseContext Current
{
get { return GuardedCache().Current; }
}
public IDatabaseContext Current => GuardedCache().Current;

public void Use(string name)
public ActiveDatabaseContext Use(string name)
{
GuardedCache().Use(name);
return GuardedCache().Use(name);
}

public void Use(IDatabaseContext context)
public ActiveDatabaseContext Use(IDatabaseContext context)
{
GuardedCache().Use(context);
return GuardedCache().Use(context);
}

public bool Contains(string connectionString)
Expand All @@ -29,7 +26,6 @@ public bool Contains(string connectionString)
public void Add(IDatabaseContext context)
{
GuardedCache().Add(context);
GuardedCache().Use(context);
}

public void Remove(IDatabaseContext context)
Expand Down

0 comments on commit cab8fd4

Please sign in to comment.