服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-04-15 c00956f6649cc13b094ec83cc3121e7cb0027b3c
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
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.WindowsServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Rhea.Common;
using Tiger.IBusiness;
 
namespace Tiger.Api
{
    internal class ApiWebHostService : WebHostService
    {
        public ApiWebHostService(IWebHost host) : base(host)
        {
           
        }
 
        protected override void OnStarting(string[] args)
        {
            Logger.Default.Info("Run Api as Windows Services");
            base.OnStarting(args);
        }
 
        protected override void OnStarted()
        {
            base.OnStarted();
            Logger.Default.Info("Api Service is started");
        }
 
        protected override void OnStopping()
        {
            try
            {
                Logger.Default.Info("Stopping Api Service");
                //关闭Api监控总线
                DI.Resolve<IMonitorBus>().StopMonitors();
                //关闭服务总线
                DI.Resolve<IServicesBus>().StopServices();
                //关闭DB缓存自动更新
                DI.Resolve<IDbCacheBus>().StopAutoUpdate();
                MQTTHelper.MQTTConn?.Close();
                base.OnStopping();
            }
            catch (System.Exception ex)
            {
                Logger.Default.Fatal(ex, "Api Service stop exception");
            }
        }
 
        protected override void OnStopped()
        {
            base.OnStopped();
            Logger.Default.Info("Api Service is stopped");
        }
 
        protected override void OnShutdown()
        {
            base.OnShutdown();
            Logger.Default.Info("Api Service is shut down");
        }
    }
}