mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 16:46:37 +08:00
feat(core): bind request services and implement registered tasks
Wire plugin services through Bind/InjectFrom and AppContext so HTTP and workers resolve dependencies after Apply. Register TaskHandler objects with persisted results, and implement send_email_code, mail:send, cleanup_inactive_users, and dispatch_bot_msg.
This commit is contained in:
@@ -201,13 +201,17 @@ func Using3[T1, T2, T3 any](ctx *Context, fn func(s1 T1, s2 T2, s3 T3)) error {
|
||||
|
||||
// When registers a reactive hook that is called immediately if T is already provided,
|
||||
// or called as soon as T is provided in the future.
|
||||
//
|
||||
// Listeners are stored on the root container so they observe core.Provide, which
|
||||
// always writes to the root. Registering on a Fiber child container would miss
|
||||
// services provided by plugins that load later.
|
||||
func When[T any](ctx *Context, fn func(s T)) {
|
||||
if ctx == nil {
|
||||
panic("core: nil context provided to When")
|
||||
}
|
||||
|
||||
targetType := reflect.TypeFor[T]()
|
||||
c := ctx.Container()
|
||||
c := ctx.Root().Container()
|
||||
|
||||
// If already ready, execute immediately
|
||||
if s, err := Inject[T](ctx); err == nil {
|
||||
@@ -223,3 +227,9 @@ func When[T any](ctx *Context, fn func(s T)) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Bind is When with a name that matches plugin wiring: fill a dependency as
|
||||
// soon as the root container provides it.
|
||||
func Bind[T any](ctx *Context, fn func(s T)) {
|
||||
When(ctx, fn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user