-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Manage blog settings #23 - UpdateBlogSettingsCommand - BlogSettings db migration * BlogSettingsConfigurationProvider and EntityChangeWatcher * change to IOptionsSnapshot
- Loading branch information
1 parent
b90178b
commit 3386438
Showing
56 changed files
with
1,040 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using System; | ||
using System.Data.SqlClient; | ||
|
||
namespace Opw.EntityFrameworkCore | ||
{ | ||
public static class DbContextOptionsHelper | ||
{ | ||
private static readonly InMemoryDatabaseRoot _inMemoryDatabaseRoot = new InMemoryDatabaseRoot(); | ||
|
||
public static void ConfigureOptionsBuilder(DbContextOptionsBuilder builder, string connectionString) | ||
{ | ||
if (connectionString.IndexOf("inMemory", StringComparison.InvariantCultureIgnoreCase) >= 0) | ||
{ | ||
// don't raise the error warning us that the in memory db doesn't support transactions | ||
builder.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); | ||
|
||
var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString); | ||
var dbName = connectionStringBuilder.InitialCatalog; | ||
|
||
builder.UseInMemoryDatabase(dbName, _inMemoryDatabaseRoot); | ||
} | ||
else | ||
{ | ||
builder.UseSqlServer(connectionString); | ||
} | ||
} | ||
|
||
public static Action<DbContextOptionsBuilder> Configure(string connectionString) | ||
{ | ||
return options => | ||
{ | ||
if (connectionString.IndexOf("inMemory", StringComparison.InvariantCultureIgnoreCase) >= 0) | ||
{ | ||
// don't raise the error warning us that the in memory db doesn't support transactions | ||
options.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); | ||
|
||
var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString); | ||
var dbName = connectionStringBuilder.InitialCatalog; | ||
|
||
options.UseInMemoryDatabase(dbName, _inMemoryDatabaseRoot); | ||
} | ||
else | ||
{ | ||
options.UseSqlServer(connectionString); | ||
} | ||
}; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.EntityFrameworkCore.ChangeTracking; | ||
using System; | ||
|
||
namespace Opw.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Event arguments for events relating to tracked Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntrys. | ||
/// </summary> | ||
public class EntityChangeEventArgs : EventArgs | ||
{ | ||
/// <summary> | ||
/// The Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry for the entity. | ||
/// </summary> | ||
public EntityEntry Entry { get; } | ||
|
||
/// <summary> | ||
/// This API supports the Entity Framework Core infrastructure and is not intended | ||
/// to be used directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public EntityChangeEventArgs(EntityEntry entityEntry) | ||
{ | ||
Entry = entityEntry; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Threading; | ||
|
||
namespace Opw.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Watches for changes on entities. | ||
/// </summary> | ||
public class EntityChangeWatcher | ||
{ | ||
/// <summary> | ||
/// An event fired when an entity that is tracked by the associated Microsoft.EntityFrameworkCore.DbContext | ||
/// has moved from one Microsoft.EntityFrameworkCore.EntityState to another. | ||
/// </summary> | ||
public event EventHandler<EntityChangeEventArgs> Changed; | ||
|
||
/// <summary> | ||
/// Let the EntityChangeWatcher know an entity has changed. | ||
/// </summary> | ||
/// <param name="e">Event arguments for events relating to tracked Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntrys.</param> | ||
public void OnChanged(EntityChangeEventArgs e) | ||
{ | ||
ThreadPool.QueueUserWorkItem((_) => Changed?.Invoke(this, e)); | ||
} | ||
|
||
#region singleton | ||
|
||
private static readonly Lazy<EntityChangeWatcher> lazy = new Lazy<EntityChangeWatcher>(() => new EntityChangeWatcher()); | ||
|
||
private EntityChangeWatcher() { } | ||
|
||
/// <summary> | ||
/// Singleton instance of EntityChangeWatcher. | ||
/// </summary> | ||
public static EntityChangeWatcher Instance => lazy.Value; | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking; | ||
|
||
namespace Opw.EntityFrameworkCore | ||
{ | ||
public interface IEntityChangeWatcher | ||
{ | ||
event EventHandler<EntityEntryEventArgs> Changed; | ||
|
||
void OnChanged(EntityEntryEventArgs e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.