Skip to content

Commit 91b050b

Browse files
committed
Use Lazy instead of direct object when initializing store
1 parent 06138de commit 91b050b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

MultiTenantravenDB/DocumentStoreFactory.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ public interface IDocumentStoreFactory
88

99
public class DocumentStoreFactory : IDocumentStoreFactory
1010
{
11-
private readonly ConcurrentDictionary<string, IDocumentStore> _stores;
11+
private readonly ConcurrentDictionary<string, Lazy<IDocumentStore>> _stores;
1212

1313
public DocumentStoreFactory()
1414
{
15-
_stores = new ConcurrentDictionary<string, IDocumentStore>();
15+
_stores = new ConcurrentDictionary<string, Lazy<IDocumentStore>>();
1616
}
1717

1818
public IDocumentStore GetStore(string tenantId)
1919
{
20-
if (_stores.TryGetValue(tenantId, out IDocumentStore value))
20+
if (_stores.TryGetValue(tenantId, out var value))
2121
{
22-
return value;
22+
return value.Value;
2323
}
2424

2525
var store = new DocumentStore
@@ -30,7 +30,7 @@ public IDocumentStore GetStore(string tenantId)
3030

3131
store.Initialize();
3232

33-
_stores[tenantId] = store;
33+
_stores[tenantId] = new Lazy<IDocumentStore>(store);
3434

3535
return store;
3636
}

0 commit comments

Comments
 (0)