-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redis repository design improvement (#79)
* Update version * Correct some file to better abstraction
- Loading branch information
1 parent
d17597a
commit 6a41667
Showing
20 changed files
with
347 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mode: ContinuousDelivery | ||
next-version: 1.14.0 | ||
next-version: 1.15.0 | ||
branches: {} | ||
ignore: | ||
sha: [] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using BSN.Commons.Infrastructure; | ||
using BSN.Commons.Infrastructure.Redis; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace BSN.Commons.Orm.Redis | ||
{ | ||
/// <summary> | ||
/// Database Factory for Redis | ||
/// </summary> | ||
public class DatabaseFactory<TDbContext> : Disposable, IDatabaseFactory where TDbContext : Redis.DbContext, ICreatable<IOptions<RedisConnectionOptions>, TDbContext> | ||
{ | ||
/// <summary> | ||
/// Constructor of Redis Database Factory | ||
/// </summary> | ||
/// <param name="configuration">App configuration</param> | ||
public DatabaseFactory(IConfiguration configuration) | ||
{ | ||
redisConnectionOptions = Options.Create(configuration.GetSection("Redis").Get<RedisConnectionOptions>()); | ||
} | ||
|
||
/// <summary> | ||
/// Constructor of Redis Database Factory | ||
/// </summary> | ||
/// <param name="options"></param> | ||
public DatabaseFactory(IOptions<RedisConnectionOptions> options) | ||
{ | ||
redisConnectionOptions = options; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IDbContext Get() | ||
{ | ||
return _redisDbContext ?? (_redisDbContext = TDbContext.Create(RedisConnectionOptions)); | ||
} | ||
|
||
/// <summary> | ||
/// Redis Connection Options | ||
/// </summary> | ||
protected IOptions<RedisConnectionOptions> RedisConnectionOptions => redisConnectionOptions; | ||
|
||
private readonly IOptions<RedisConnectionOptions> redisConnectionOptions; | ||
private IDbContext _redisDbContext; | ||
} | ||
} |
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,47 @@ | ||
using BSN.Commons.Infrastructure; | ||
using BSN.Commons.Infrastructure.Redis; | ||
using Microsoft.Extensions.Options; | ||
using Redis.OM; | ||
using Redis.OM.Contracts; | ||
using Redis.OM.Searching; | ||
using StackExchange.Redis; | ||
|
||
namespace BSN.Commons.Orm.Redis | ||
{ | ||
/// <summary> | ||
/// Redis Database Context | ||
/// </summary> | ||
public class DbContext : RedisConnectionProvider, IDbContext, ICreatable<IOptions<RedisConnectionOptions>, DbContext> | ||
{ | ||
/// <summary> | ||
/// Constructor of Redis Database Context | ||
/// </summary> | ||
/// <param name="options">Redis Connection Options</param> | ||
public DbContext(IOptions<RedisConnectionOptions> options) | ||
: base(options.Value.ConnectionString) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Static factory method to create a new instance of the <see cref="DbContext"/> | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
public static DbContext Create(IOptions<RedisConnectionOptions> options) | ||
{ | ||
return new DbContext(options); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public virtual int SaveChanges() | ||
{ | ||
throw new System.NotImplementedException("We don't have a way to save changes on redis om yet."); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Dispose() | ||
{ | ||
// TODO release managed resources here | ||
} | ||
} | ||
} |
Oops, something went wrong.