Netcore: Replace IUmbracoRequestLifetime with EventAggregator nofitications (#9711)
* AB#9928 - Replace IUmbracoRequestLifetime with event aggregator * AB#9928 - Fix issue with profiling, by calling it explicitly in the request middleware * Longer timeout to avoid flaky test * Longer timeout to avoid flaky test Co-authored-by: Elitsa Marinovska <elm@umbraco.dk>
This commit is contained in:
@@ -4,13 +4,13 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.Web.Common.Lifetime;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Common.AspNetCore
|
||||
{
|
||||
public class AspNetCoreRequestAccessor : IRequestAccessor
|
||||
public class AspNetCoreRequestAccessor : IRequestAccessor, INotificationHandler<UmbracoRequestBegin>, INotificationHandler<UmbracoRequestEnd>
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
@@ -19,7 +19,6 @@ namespace Umbraco.Web.Common.AspNetCore
|
||||
private Uri _currentApplicationUrl;
|
||||
|
||||
public AspNetCoreRequestAccessor(IHttpContextAccessor httpContextAccessor,
|
||||
IUmbracoRequestLifetime umbracoRequestLifetime,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IOptions<WebRoutingSettings> webRoutingSettings)
|
||||
{
|
||||
@@ -27,20 +26,8 @@ namespace Umbraco.Web.Common.AspNetCore
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_webRoutingSettings = webRoutingSettings.Value;
|
||||
|
||||
umbracoRequestLifetime.RequestStart += RequestStart;
|
||||
umbracoRequestLifetime.RequestEnd += RequestEnd;
|
||||
}
|
||||
|
||||
private void RequestEnd(object sender, HttpContext e)
|
||||
{
|
||||
EndRequest?.Invoke(sender, new UmbracoRequestEventArgs(_umbracoContextAccessor.UmbracoContext));
|
||||
}
|
||||
|
||||
private void RequestStart(object sender, HttpContext e)
|
||||
{
|
||||
var reason = EnsureRoutableOutcome.IsRoutable; //TODO get the correct value here like in UmbracoInjectedModule
|
||||
RouteAttempt?.Invoke(sender, new RoutableAttemptEventArgs(reason, _umbracoContextAccessor.UmbracoContext));
|
||||
}
|
||||
|
||||
public string GetRequestValue(string name) => GetFormValue(name) ?? GetQueryStringValue(name);
|
||||
|
||||
@@ -92,5 +79,18 @@ namespace Umbraco.Web.Common.AspNetCore
|
||||
|
||||
return _currentApplicationUrl;
|
||||
}
|
||||
|
||||
public void Handle(UmbracoRequestBegin notification)
|
||||
{
|
||||
var reason = EnsureRoutableOutcome.IsRoutable; //TODO get the correct value here like in UmbracoInjectedModule
|
||||
RouteAttempt?.Invoke(this, new RoutableAttemptEventArgs(reason, _umbracoContextAccessor.UmbracoContext));
|
||||
}
|
||||
|
||||
public void Handle(UmbracoRequestEnd notification)
|
||||
{
|
||||
EndRequest?.Invoke(this, new UmbracoRequestEventArgs(_umbracoContextAccessor.UmbracoContext));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user