File tree Expand file tree Collapse file tree 1 file changed +21
-7
lines changed
Expand file tree Collapse file tree 1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -12,24 +12,38 @@ namespace Demo
1212 class Program
1313 {
1414 static void Main ( string [ ] args )
15+ {
16+ Program . Init ( ) ;
17+ Program . RequestAsync ( ) . Wait ( ) ;
18+ Console . ReadLine ( ) ;
19+ }
20+
21+ /// <summary>
22+ /// 初始化配置
23+ /// </summary>
24+ static void Init ( )
1525 {
1626 HttpServer . Start ( 9999 ) ;
1727
28+ // 注册与配置IUserApi接口
1829 HttpApiFactory . Add < IUserApi > ( c =>
1930 {
2031 c . HttpHost = new Uri ( "http://localhost:9999/" ) ;
2132 c . LoggerFactory = new LoggerFactory ( ) . AddConsole ( ) ;
33+ c . FormatOptions . DateTimeFormat = DateTimeFormats . ISO8601_WithMillisecond ;
2234 } ) ;
23-
24- var userApi = HttpApiFactory . Create < IUserApi > ( ) ;
25- Program . RequestAsync ( userApi ) . Wait ( ) ;
26-
27- Console . ReadLine ( ) ;
2835 }
2936
30-
31- private static async Task RequestAsync ( IUserApi userApi )
37+ /// <summary>
38+ /// 请求接口
39+ /// </summary>
40+ /// <returns></returns>
41+ private static async Task RequestAsync ( )
3242 {
43+ // userApi由HttpApiFactory创建,自动接管其生命周期
44+ // 不应该将其做为全局变量缓存起来
45+ var userApi = HttpApiFactory . Create < IUserApi > ( ) ;
46+
3347 var user = new UserInfo
3448 {
3549 Account = "laojiu" ,
You can’t perform that action at this time.
0 commit comments