diff --git a/Lucene.Net.IndexProvider/Lucene.Net.IndexProvider.csproj b/Lucene.Net.IndexProvider/Lucene.Net.IndexProvider.csproj
index 24738e2..9b7fbcd 100644
--- a/Lucene.Net.IndexProvider/Lucene.Net.IndexProvider.csproj
+++ b/Lucene.Net.IndexProvider/Lucene.Net.IndexProvider.csproj
@@ -8,7 +8,6 @@
-
@@ -19,7 +18,7 @@
- 1.0.27
+ 1.0.28
https://github.com/ssinno28/Lucene.Net.IndexProvider
git
A simple service that helps to abstract common operations when interacting with lucene.net indexes.
diff --git a/Lucene.Net.IndexProvider/Managers/IndexSessionManager.cs b/Lucene.Net.IndexProvider/Managers/IndexSessionManager.cs
index b310411..0dcdc32 100644
--- a/Lucene.Net.IndexProvider/Managers/IndexSessionManager.cs
+++ b/Lucene.Net.IndexProvider/Managers/IndexSessionManager.cs
@@ -1,33 +1,32 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.IO;
-using System.Linq;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Index;
using Lucene.Net.IndexProvider.Interfaces;
using Lucene.Net.Store;
-using Microsoft.AspNetCore.Http;
namespace Lucene.Net.IndexProvider.Managers;
public class IndexSessionManager : IIndexSessionManager
{
- private readonly string SESSIONS_KEY = "INDEX_SESSIONS";
-
private readonly IIndexConfigurationManager _configurationManager;
- private readonly IHttpContextAccessor _httpContextAccessor;
- private readonly IDictionary _backupContextSessions = new Dictionary();
private readonly ILocalIndexPathFactory _localIndexPathFactory;
public IndexSessionManager(
IIndexConfigurationManager configurationManager,
- IHttpContextAccessor httpContextAccessor,
ILocalIndexPathFactory localIndexPathFactory)
{
_configurationManager = configurationManager;
- _httpContextAccessor = httpContextAccessor;
_localIndexPathFactory = localIndexPathFactory;
}
+ private readonly Lazy> _contextSessions =
+ new Lazy>(
+ () => new Dictionary (StringComparer.OrdinalIgnoreCase));
+
+ public IDictionary ContextSessions => _contextSessions.Value;
+
public IndexWriter GetSessionFrom(string indexName)
{
if (!ContextSessions.TryGetValue(indexName, out var context))
@@ -72,23 +71,4 @@ public void CloseSessionOn(string indexName)
ContextSessions.Remove(indexName);
}
}
-
- public IDictionary ContextSessions
- {
- get
- {
- if (_httpContextAccessor.HttpContext == null)
- {
- return _backupContextSessions;
- }
-
- if (!_httpContextAccessor.HttpContext.Items.TryGetValue(SESSIONS_KEY, out var sessions))
- {
- sessions = new Dictionary();
- _httpContextAccessor.HttpContext.Items.Add(SESSIONS_KEY, sessions);
- }
-
- return (IDictionary)sessions;
- }
- }
}
\ No newline at end of file