1
+ using System ;
2
+ using System . IO ;
3
+ using Microsoft . AspNetCore . Builder ;
4
+ using Microsoft . AspNetCore . Hosting ;
5
+ using Microsoft . Extensions . DependencyInjection ;
6
+ using Microsoft . Extensions . Logging ;
7
+ using SmartSqlSampleChapterThree . DomainService ;
8
+ using Swashbuckle . AspNetCore . Swagger ;
9
+
10
+ namespace SmartSqlSampleChapterThree . Api
11
+ {
12
+ public class Startup
13
+ {
14
+ // This method gets called by the runtime. Use this method to add services to the container.
15
+ // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
16
+ public void ConfigureServices ( IServiceCollection services )
17
+ {
18
+ services . AddMvcCore ( ) ;
19
+
20
+ services . AddLogging ( logging =>
21
+ {
22
+ logging . SetMinimumLevel ( LogLevel . Trace ) ;
23
+ logging . AddConsole ( ) ;
24
+ } ) ;
25
+
26
+ // register smartsql
27
+ services . AddSmartSql ( builder =>
28
+ {
29
+ builder . UseAlias ( "SmartSqlSampleChapterThree" ) ; // 定义实例别名,在多库场景下适用。
30
+ } ) . AddRepositoryFromAssembly ( options =>
31
+ {
32
+ // SmartSql实例的别名
33
+ options . SmartSqlAlias = "SmartSqlSampleChapterThree" ;
34
+ // 仓储接口所在的程序集全称
35
+ options . AssemblyString = "SmartSqlSampleChapterThree.Repository" ;
36
+ } ) ;
37
+
38
+ // register domain service
39
+ services . AddSingleton < IUserDomainService , NormalUserDomainService > ( ) ;
40
+
41
+ // register swagger
42
+ services . AddSwaggerGen ( c =>
43
+ {
44
+ c . SwaggerDoc ( "SmartSqlSampleChapterThree" , new Info
45
+ {
46
+ Title = "SmartSqlSampleChapterThree" ,
47
+ Version = "v1" ,
48
+ Description = "SmartSqlSampleChapterThree"
49
+ } ) ;
50
+ var filePath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "SmartSqlSampleChapterThree.Api.xml" ) ;
51
+ if ( File . Exists ( filePath ) ) c . IncludeXmlComments ( filePath ) ;
52
+ } ) ;
53
+ }
54
+
55
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
56
+ public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
57
+ {
58
+ if ( env . IsDevelopment ( ) ) app . UseDeveloperExceptionPage ( ) ;
59
+ app . UseMvc ( ) ;
60
+
61
+ app . UseSwagger ( c => { } ) ;
62
+ app . UseSwaggerUI ( c => { c . SwaggerEndpoint ( "/swagger/SmartSqlSampleChapterThree/swagger.json" , "SmartSqlSampleChapterThree" ) ; } ) ;
63
+ }
64
+ }
65
+ }
0 commit comments