Skip to content
Browse files

Update LuceneIndexingService to use Ninject EF DbContext for any give…

…n creation or deletion of a package on the feed. WebBackgrounder task will use default constructor that news up a DbContext.
  • Loading branch information...
1 parent 41a8ab0 commit 40e0762ff8605072b0d82acafdd94aeb756febe6 @chappoo chappoo committed with pranavkm Sep 10, 2012
Showing with 14 additions and 8 deletions.
  1. +14 −8 Website/Infrastructure/Lucene/LuceneIndexingService.cs
View
22 Website/Infrastructure/Lucene/LuceneIndexingService.cs
@@ -9,16 +9,28 @@
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
+using Ninject;
namespace NuGetGallery
{
public class LuceneIndexingService : IIndexingService
{
+ private readonly DbContext _entitiesContext;
private static readonly object indexWriterLock = new object();
private static readonly TimeSpan indexRecreateInterval = TimeSpan.FromDays(3);
private static readonly char[] idSeparators = new[] { '.', '-' };
private static IndexWriter indexWriter;
+ public LuceneIndexingService() : this(new EntitiesContext())
+ {
+ }
+
+ [Inject]
+ public LuceneIndexingService(IEntitiesContext entitiesContext)
+ {
+ _entitiesContext = (DbContext)entitiesContext;
+ }
+
public void UpdateIndex()
{
DateTime? lastWriteTime = GetLastWriteTime();
@@ -37,10 +49,9 @@ public void UpdateIndex()
// Set the index create time to now. This would tell us when we last rebuilt the index.
UpdateIndexRefreshTime();
}
-
- using (var context = CreateContext())
+ if (_entitiesContext != null)
{
- var packages = GetPackages(context, lastWriteTime);
+ var packages = GetPackages(_entitiesContext, lastWriteTime);
if (packages.Count > 0)
{
AddPackages(packages);
@@ -49,11 +60,6 @@ public void UpdateIndex()
UpdateLastWriteTime();
}
- protected internal virtual DbContext CreateContext()
- {
- return new EntitiesContext();
- }
-
protected internal virtual List<PackageIndexEntity> GetPackages(DbContext context, DateTime? lastIndexTime)
{
string sql = @"SELECT p.[Key], pr.Id, p.Title, p.Description, p.Tags, p.FlattenedAuthors as Authors, pr.DownloadCount,

0 comments on commit 40e0762

Please sign in to comment.
Something went wrong with that request. Please try again.