Skip to content

Commit

Permalink
Add support for singleton based LiteDB implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangeeth Nandakumar committed Jan 21, 2024
1 parent f6f89d1 commit b4b88b0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Twileloop.UOW.LiteDB/Support/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ namespace Twileloop.UOW.LiteDB.Support

public static class Extensions
{
public static void AddSingletonUnitOfWork(this IServiceCollection services, Action<Options>? options = null)
{
var uowOptions = new Options();
options?.Invoke(uowOptions);

var contexts = new ConcurrentDictionary<string, LiteDBContext>();
foreach (var conn in uowOptions.Connections)
{
var db = new LiteDatabase(conn.ConnectionString);
contexts.TryAdd(conn.Name, new LiteDBContext(conn.Name, db));
}

services.AddSingleton(contexts);
services.AddSingleton<UnitOfWork>();
}

public static void AddUnitOfWork(this IServiceCollection services, Action<Options>? options = null)
{
var uowOptions = new Options();
Expand Down

0 comments on commit b4b88b0

Please # to comment.