forked from Lombiq/Orchard-Training-Demo-Module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
134 lines (115 loc) · 5.93 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.IO;
using Fluid;
using Lombiq.TrainingDemo.Drivers;
using Lombiq.TrainingDemo.Fields;
using Lombiq.TrainingDemo.Filters;
using Lombiq.TrainingDemo.Indexes;
using Lombiq.TrainingDemo.Indexing;
using Lombiq.TrainingDemo.Migrations;
using Lombiq.TrainingDemo.Models;
using Lombiq.TrainingDemo.Navigation;
using Lombiq.TrainingDemo.Permissions;
using Lombiq.TrainingDemo.Services;
using Lombiq.TrainingDemo.Settings;
using Lombiq.TrainingDemo.ViewModels;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OrchardCore.BackgroundTasks;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentTypes.Editors;
using OrchardCore.Data.Migration;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Environment.Shell;
using OrchardCore.Indexing;
using OrchardCore.Modules;
using OrchardCore.Navigation;
using OrchardCore.ResourceManagement;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using YesSql.Indexes;
namespace Lombiq.TrainingDemo
{
public class Startup : StartupBase
{
static Startup()
{
// To be able to access these view models in display shapes rendered by the Liquid markup engine you need
// to register them. To learn more about Liquid in Orchard Core see this documentation:
// https://orchardcore.readthedocs.io/en/latest/OrchardCore.Modules/OrchardCore.Liquid/README/
TemplateContext.GlobalMemberAccessStrategy.Register<PersonPartViewModel>();
TemplateContext.GlobalMemberAccessStrategy.Register<ColorField>();
TemplateContext.GlobalMemberAccessStrategy.Register<DisplayColorFieldViewModel>();
// NEXT STATION: Views/PersonPart.Edit.cshtml
}
public override void ConfigureServices(IServiceCollection services)
{
// Book
services.AddScoped<IDisplayDriver<Book>, BookDisplayDriver>();
services.AddScoped<IDisplayManager<Book>, DisplayManager<Book>>();
services.AddScoped<IDataMigration, BookMigrations>();
services.AddSingleton<IIndexProvider, BookIndexProvider>();
// Person Part
services.AddSingleton<ContentPart, PersonPart>();
services.AddScoped<IDataMigration, PersonMigrations>();
services.AddScoped<IContentPartDisplayDriver, PersonPartDisplayDriver>();
services.AddSingleton<IIndexProvider, PersonPartIndexProvider>();
// Color Field
services.AddSingleton<ContentField, ColorField>();
services.AddScoped<IContentFieldDisplayDriver, ColorFieldDisplayDriver>();
services.AddScoped<IContentPartFieldDefinitionDisplayDriver, ColorFieldSettingsDriver>();
services.AddScoped<IContentFieldIndexHandler, ColorFieldIndexHandler>();
// Resources
services.AddScoped<IResourceManifestProvider, ResourceManifest>();
// Permissions
services.AddScoped<IPermissionProvider, PersonPermissions>();
// Admin Menu
services.AddScoped<INavigationProvider, PersonsAdminMenu>();
// Demo Settings
services.AddScoped<IDisplayDriver<ISite>, DemoSettingsDisplayDriver>();
services.AddScoped<IPermissionProvider, DemoSettingsPermissions>();
services.AddScoped<INavigationProvider, DemoSettingsAdminMenu>();
// Filters
services.Configure<MvcOptions>((options) =>
{
options.Filters.Add(typeof(ShapeInjectionFilter));
options.Filters.Add(typeof(ResourceInjectionFilter));
});
// File System
services.AddSingleton<ICustomFileStore>(serviceProvider =>
{
// So our goal here is to have a custom folder in the tenant's own folder. The Media folder is also
// there but we won't use that. To get tenant-specific data we need to use the ShellOptions and
// ShellShettings objects.
var shellOptions = serviceProvider.GetRequiredService<IOptions<ShellOptions>>().Value;
var shellSettings = serviceProvider.GetRequiredService<ShellSettings>();
var tenantFolderPath = PathExtensions.Combine(
// This is the absolute path of the "App_Data" folder.
shellOptions.ShellsApplicationDataPath,
// This is the folder which contains the tenants which is Sites by default.
shellOptions.ShellsContainerName,
// This is the tenant name. We want our custom folder inside this folder.
shellSettings.Name);
// And finally our full base path.
var customFolderPath = PathExtensions.Combine(tenantFolderPath, "CustomFiles");
// Now register our CustomFileStore instance with the path given.
return new CustomFileStore(customFolderPath);
// NEXT STATION: Controllers/FileManagementController and find the CreateFileInCustomFolder method.
});
// Caching
services.AddScoped<IDateTimeCachingService, DateTimeCachingService>();
// Background tasks
services.AddSingleton<IBackgroundTask, DemoBackgroundTask>();
}
public override void Configure(IApplicationBuilder builder, IRouteBuilder routes, IServiceProvider serviceProvider)
{
// You can put service configuration here as you would do it in other ASP.NET Core applications. If you
// don't need it you can skip overriding it.
}
}
}