-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathSiteStartup.cs
71 lines (61 loc) · 2.55 KB
/
SiteStartup.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
using OrchardCore.Data.YesSql;
using OrchardCore.Modules;
using OrchardCore.Modules.Manifest;
using OrchardCore.Recipes.Services;
namespace OrchardCore.Tests.Apis.Context
{
public class SiteStartup
{
public static readonly ConcurrentDictionary<string, PermissionsContext> PermissionsContexts;
static SiteStartup()
{
PermissionsContexts = new ConcurrentDictionary<string, PermissionsContext>();
}
#pragma warning disable CA1822 // Mark members as static
public void ConfigureServices(IServiceCollection services)
#pragma warning restore CA1822 // Mark members as static
{
services.AddOrchardCms(builder =>
builder.AddSetupFeatures(
"OrchardCore.Tenants"
)
.AddTenantFeatures(
"OrchardCore.Apis.GraphQL"
)
.ConfigureServices(collection =>
{
collection.Configure<YesSqlOptions>(options =>
{
// To ensure we don't encounter any concurrent issue, enable EnableThreadSafetyChecks for all test.
options.EnableThreadSafetyChecks = true;
});
collection.AddScoped<IRecipeHarvester, TestRecipeHarvester>();
collection.AddScoped<IAuthorizationHandler, PermissionContextAuthorizationHandler>(sp =>
{
return new PermissionContextAuthorizationHandler(sp.GetRequiredService<IHttpContextAccessor>(), PermissionsContexts);
});
})
.Configure(appBuilder => appBuilder.UseAuthorization()));
services.AddSingleton<IModuleNamesProvider, ModuleNamesProvider>();
}
#pragma warning disable CA1822 // Mark members as static
public void Configure(IApplicationBuilder app)
#pragma warning restore CA1822 // Mark members as static
{
app.UseOrchardCore();
}
private sealed class ModuleNamesProvider : IModuleNamesProvider
{
private readonly string[] _moduleNames;
public ModuleNamesProvider()
{
var assembly = Assembly.Load(new AssemblyName(typeof(Program).Assembly.GetName().Name));
_moduleNames = assembly.GetCustomAttributes<ModuleNameAttribute>().Select(m => m.Name).ToArray();
}
public IEnumerable<string> GetModuleNames()
{
return _moduleNames;
}
}
}
}