forked from simplcommerce/SimplCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.cs
More file actions
79 lines (66 loc) · 2.79 KB
/
Startup.cs
File metadata and controls
79 lines (66 loc) · 2.79 KB
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
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using SimplCommerce.Infrastructure;
using SimplCommerce.Infrastructure.Web;
using SimplCommerce.Module.Localization;
using SimplCommerce.WebHost.Extensions;
namespace SimplCommerce.WebHost
{
public class Startup
{
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
{
_configuration = configuration;
_hostingEnvironment = hostingEnvironment;
}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
GlobalConfiguration.WebRootPath = _hostingEnvironment.WebRootPath;
GlobalConfiguration.ContentRootPath = _hostingEnvironment.ContentRootPath;
services.LoadInstalledModules(_hostingEnvironment.ContentRootPath);
services.AddCustomizedDataStore(_configuration);
services.AddCustomizedIdentity();
services.AddSingleton<IStringLocalizerFactory, EfStringLocalizerFactory>();
services.AddCloudscribePagination();
services.Configure<RazorViewEngineOptions>(
options => { options.ViewLocationExpanders.Add(new ModuleViewLocationExpander()); });
services.AddCustomizedMvc(GlobalConfiguration.Modules);
var sp = services.BuildServiceProvider();
var moduleInitializers = sp.GetServices<IModuleInitializer>();
foreach (var moduleInitializer in moduleInitializers)
{
moduleInitializer.ConfigureServices(services);
}
return services.Build(_configuration, _hostingEnvironment);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStatusCodePagesWithReExecute("/Home/ErrorWithCode/{0}");
app.UseCustomizedRequestLocalization();
app.UseCustomizedStaticFiles(env);
app.UseCustomizedIdentity();
app.UseCustomizedMvc();
var moduleInitializers = app.ApplicationServices.GetServices<IModuleInitializer>();
foreach (var moduleInitializer in moduleInitializers)
{
moduleInitializer.Configure(app, env);
}
}
}
}