feat(core): implement plugin fiber state machine and reactive dependency reconciler

This commit is contained in:
ryan
2026-08-28 13:35:43 +08:00
parent 33294b3fae
commit 3570ccd5c3
7 changed files with 404 additions and 18 deletions
+20 -1
View File
@@ -46,7 +46,7 @@ func (c *Container) remove(targetType reflect.Type) {
delete(c.services, targetType)
}
// Provide registers a typed service implementation into the Context's IoC container.
// Provide registers a typed service implementation into the Context hierarchy's root IoC container.
func Provide[T any](ctx *Context, service T) {
if ctx == nil {
panic("core: nil context provided to Provide")
@@ -55,6 +55,25 @@ func Provide[T any](ctx *Context, service T) {
panic("core: cannot provide nil service")
}
targetType := reflect.TypeFor[T]()
targetContainer := ctx.Root().Container()
targetContainer.provide(targetType, service)
ctx.OnDispose(func() error {
targetContainer.remove(targetType)
return nil
})
}
// ProvideScoped registers a typed service implementation strictly in the local Context container.
func ProvideScoped[T any](ctx *Context, service T) {
if ctx == nil {
panic("core: nil context provided to ProvideScoped")
}
if isNil(service) {
panic("core: cannot provide nil service")
}
targetType := reflect.TypeFor[T]()
targetContainer := ctx.Container()
targetContainer.provide(targetType, service)