-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
executable file
·80 lines (69 loc) · 2.42 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
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Ticketing.Apps.Channels.Areas.Account.Models.Home.Mappers;
using Ticketing.Apps.Channels.Infrastructure.Accessors;
using Ticketing.Services.Customers;
#nullable enable
namespace Ticketing.Apps.Channels;
public class Startup
{
private readonly IConfiguration configuration;
private readonly IHostEnvironment hostEnvironment;
public Startup(
IConfiguration configuration,
IHostEnvironment hostEnvironment)
{
this.configuration = configuration;
this.hostEnvironment = hostEnvironment;
}
public void ConfigureServices(IServiceCollection services)
{
// configure IHttpContextAccessor to get hold of HttpContext
services.AddHttpContextAccessor();
// configure routing
services.AddRouting(options =>
{
options.LowercaseUrls = true;
});
// configure mvc w/global filters
services
.AddMvc(/*setupAction ?? ((options) => { })*/)
.AddControllersAsServices() // resolve controllers using autofac
.AddMvcOptions(options =>
{
// allow optional FromBody ..=null parameters
options.AllowEmptyInputInBodyModelBinding = true;
})
.AddJsonOptions(options => // configure system.text.json with our 'defaults'
{
})
.AddCookieTempDataProvider(options => // use cookies for temp data
{
options.Cookie.Name = "mvcTempData"; // default = .AspNetCore.Mvc.CookieTempDataProvider
});
}
public void ConfigureContainer(ContainerBuilder b)
{
b.RegisterType<ChannelContextAccessor>().AsImplementedInterfaces().SingleInstance();
b.RegisterType<PurchasingCustomerContextAccessor>().AsImplementedInterfaces().SingleInstance();
b.RegisterType<AccountMapper>().AsSelf().AsImplementedInterfaces().SingleInstance();
b.RegisterType<AccountService>().AsSelf().AsImplementedInterfaces().SingleInstance();
}
public void Configure(
IApplicationBuilder app,
IHostApplicationLifetime applicationLifetime,
ILogger<Startup> log)
{
// add response compression middleware (doesn't work under dotnet watch)
if (Environment.GetEnvironmentVariable("DOTNET_WATCH") == null)
app.UseResponseCompression();
// enable end-point routing
app.UseRouting();
// enable mvc & signalr middleware
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("areaRoute", "{area:exists}/{controller=Home}/{action=Index}");
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
}
}