@@ -29,17 +29,11 @@ import (
2929
3030 "github.com/go-spring-projects/go-spring/conf"
3131 "github.com/go-spring-projects/go-spring/gs/arg"
32- "github.com/go-spring-projects/go-spring/internal/utils"
3332)
3433
35- // AppRunner .
36- type AppRunner interface {
37- Run (ctx Context )
38- }
39-
4034// AppEvent start and stop events
4135type AppEvent interface {
42- OnAppStart (ctx Context )
36+ OnAppStart (ctx context. Context )
4337 OnAppStop (ctx context.Context )
4438}
4539
@@ -87,9 +81,7 @@ func (app *App) run(resourceLocator ResourceLocator) error {
8781 return err
8882 }
8983
90- var logger = GetLogger ("" , utils .TypeName (app ))
91-
92- app .onAppRun (app .container )
84+ var logger = GetLogger ()
9385
9486 app .onAppStart (app .container )
9587
@@ -105,7 +97,7 @@ func (app *App) run(resourceLocator ResourceLocator) error {
10597
10698 <- app .exitChan
10799
108- app .onAppStop (context . Background () )
100+ app .onAppStop (app . container )
109101
110102 app .container .Close ()
111103
@@ -114,32 +106,24 @@ func (app *App) run(resourceLocator ResourceLocator) error {
114106 return nil
115107}
116108
117- func (app * App ) onAppRun (ctx Context ) {
118- for _ , bean := range app .container .Dependencies (true ) {
119- x := bean .Value ().Interface ()
120-
121- if ar , ok := x .(AppRunner ); ok {
122- ar .Run (ctx )
123- }
124- }
125- }
126-
127109func (app * App ) onAppStart (ctx Context ) {
110+ gsCtx := WithContext (ctx .Context (), ctx )
128111 for _ , bean := range app .container .Dependencies (true ) {
129112 x := bean .Value ().Interface ()
130113
131114 if ae , ok := x .(AppEvent ); ok {
132- ae .OnAppStart (ctx )
115+ ae .OnAppStart (gsCtx )
133116 }
134117 }
135118}
136119
137- func (app * App ) onAppStop (ctx context.Context ) {
120+ func (app * App ) onAppStop (ctx Context ) {
121+ gsCtx := WithContext (context .Background (), ctx )
138122 for _ , bean := range app .container .Dependencies (false ) {
139123 x := bean .Value ().Interface ()
140124
141125 if ae , ok := x .(AppEvent ); ok {
142- ae .OnAppStop (ctx )
126+ ae .OnAppStop (gsCtx )
143127 }
144128 }
145129}
@@ -184,7 +168,7 @@ func (app *App) Shutdown(msg ...string) {
184168 case <- app .exitChan :
185169 // app already closed
186170 default :
187- var logger = GetLogger ("" , utils . TypeName ( app ) )
171+ var logger = GetLogger ()
188172 logger .Info (fmt .Sprintf ("program will exit %s" , strings .Join (msg , ", " )))
189173 close (app .exitChan )
190174 }
0 commit comments