41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Microsoft.Practices.Unity;
|
|
using Microsoft.Practices.Unity.InterceptionExtension;
|
|
using Portoa.Search;
|
|
using VideoGameQuotes.Api;
|
|
|
|
namespace VideoGameQuotes.Web.Configuration {
|
|
/// <summary>
|
|
/// Call handler that updates the index for a quote whenever it's updated
|
|
/// </summary>
|
|
public class UpdateSearchIndexCallHandler : ICallHandler {
|
|
private readonly IUnityContainer container;
|
|
|
|
/// <remarks>
|
|
/// Can't inject ISearchIndexBuilder because it causes an infinite loop
|
|
/// while trying to instantiate the call handler. So we do a later resolve
|
|
/// using the container on the index builder so that this shit fucking works.
|
|
/// </remarks>
|
|
public UpdateSearchIndexCallHandler(IUnityContainer container) {
|
|
this.container = container;
|
|
}
|
|
|
|
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) {
|
|
var returnValue = getNext()(input, getNext);
|
|
if (returnValue.Exception != null) {
|
|
//if the update failed then just return
|
|
return returnValue;
|
|
}
|
|
|
|
var quote = returnValue.ReturnValue as Quote;
|
|
if (quote == null || !quote.ShouldIndex) {
|
|
return returnValue;
|
|
}
|
|
|
|
container.Resolve<ISearchIndexBuilder<Quote, int>>().UpdateIndex(quote);
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
public int Order { get; set; }
|
|
}
|
|
} |