Fix NotifierFilter

Don't assume the action is executed by a controller
This commit is contained in:
Sipke Schoorstra 2020-05-15 20:16:51 +02:00
parent 3f153c0f13
commit d3032a8a7a

View file

@ -2,6 +2,7 @@ using Elsa.Dashboard.Extensions;
using Elsa.Dashboard.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Elsa.Dashboard.ActionFilters
{
@ -9,10 +10,12 @@ namespace Elsa.Dashboard.ActionFilters
{
public const string TempDataKey = "Elsa:Notifications";
private readonly INotifier notifier;
private readonly ITempDataDictionaryFactory tempDataDictionaryFactory;
public NotifierFilter(INotifier notifier)
public NotifierFilter(INotifier notifier, ITempDataDictionaryFactory tempDataDictionaryFactory)
{
this.notifier = notifier;
this.tempDataDictionaryFactory = tempDataDictionaryFactory;
}
public void OnActionExecuting(ActionExecutingContext context)
@ -21,7 +24,7 @@ namespace Elsa.Dashboard.ActionFilters
public void OnActionExecuted(ActionExecutedContext context)
{
var tempData = ((Controller) context.Controller).TempData;
var tempData = tempDataDictionaryFactory.GetTempData(context.HttpContext);
if (tempData.ContainsKey(TempDataKey))
return;