using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.InterceptionExtension; using Portoa.Search; using VideoGameQuotes.Api; namespace VideoGameQuotes.Web.Configuration { /// /// Call handler that deletes the search index whenever a quote is deleted /// public class DeleteSearchIndexCallHandler : ICallHandler { private readonly IUnityContainer container; public DeleteSearchIndexCallHandler(IUnityContainer container) { this.container = container; } public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { var quoteId = (int)input.Arguments[0]; var returnValue = getNext()(input, getNext); if (returnValue.Exception != null) { return returnValue; } container.Resolve>().DeleteIndex(new Quote { Id = quoteId }); return returnValue; } public int Order { get; set; } } }