Repository navigation
Expand file tree
/
Copy pathStartup.cs
More file actions
100 lines (81 loc) · 3.44 KB
/
Copy pathStartup.cs
File metadata and controls
100 lines (81 loc) · 3.44 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Autofac;
using Autofac.Annotation;
using Autofac.Extensions.DependencyInjection;
using Infrastructure.View;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Serialization;
using NLog.Extensions.Logging;
using Repository;
using System;
using ant.mgr.core.Filter;
namespace ant.mgr.core
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddCors(o => o.AddPolicy("Any", r =>
{
r.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));
services.AddScoped<IViewRenderService, ViewRenderService>();
services.AddMvc(o => { o.Filters.Add<GlobalExceptionFilter>(); })
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
.AddControllersAsServices();
services.AddHttpContextAccessor();
var builder = new ContainerBuilder();
builder.Populate(services);
//autofac打标签模式 文档:https://github.com/yuzd/Autofac.Annotation
builder.RegisterModule(new AutofacAnnotationModule(this.GetType().Assembly, typeof(BaseRepository<>).Assembly)
.SetAllowCircularDependencies(true)
.InstancePerLifetimeScope());
var container = builder.Build();
var serviceProvider = new AutofacServiceProvider(container);
Infrastructure.Web.HttpContext.ServiceProvider = serviceProvider;
return serviceProvider;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logging)
{
#region AntORM
//文档:https://github.com/yuzd/AntData.ORM
AntData.ORM.Common.Configuration.UseDBConfig(Configuration);
AntData.ORM.Common.Configuration.Linq.AllowMultipleQuery = true;
#endregion
#region NLOG
NLog.LogManager.LoadConfiguration("nlog.config");
logging.AddNLog();
#endregion
#region AutoMapperConfig
var autoMapperConfig = new Mapping.AutoMapper();
autoMapperConfig.ExecuteByAssemblyName("DbModel", "ServicesModel");
#endregion
app.UseStaticFiles();
app.UseStatusCodePagesWithReExecute("/admin/error/{0}");
app.UseMvc(routes =>
{
// areas
routes.MapRoute(
name: "Admin",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}