-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
58 lines (49 loc) · 2.11 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Etch.OrchardCore.OutputCache.Controllers;
using Etch.OrchardCore.OutputCache.Drivers;
using Etch.OrchardCore.OutputCache.Policies;
using Etch.OrchardCore.OutputCache.Settings;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Entities;
using OrchardCore.Modules;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Navigation;
using OrchardCore.Settings;
using System;
namespace Etch.OrchardCore.OutputCache
{
public class Startup : StartupBase
{
private readonly AdminOptions _adminOptions;
public Startup(IOptions<AdminOptions> adminOptions)
{
_adminOptions = adminOptions.Value;
}
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDisplayDriver<ISite>, OutputCacheSettingsDisplayDriver>();
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddOutputCache(options =>
{
var siteService = services.BuildServiceProvider().GetService<ISiteService>();
var settings = siteService.GetSiteSettingsAsync().Result.As<OutputCacheSettings>();
options.DefaultExpirationTimeSpan = new TimeSpan(0, settings.Expiration, 0);
options.AddBasePolicy(new DefaultOrchardCorePolicy(settings));
});
}
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
{
app.UseOutputCache();
routes.MapAreaControllerRoute(
name: "OutputCachePurge",
areaName: "Etch.OrchardCore.OutputCache",
pattern: _adminOptions.AdminUrlPrefix + "/OutputCache/Purge",
defaults: new { controller = typeof(PurgeController).ControllerName(), action = nameof(PurgeController.Index) }
);
}
}
}