优化结构
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Package app is the composition root for the running administration service.
|
||||
// It wires runtime objects that need constructed dependencies. Static module
|
||||
// declarations live in the sibling internal/modules package.
|
||||
package app
|
||||
|
||||
import (
|
||||
"kra/pkg/module"
|
||||
platformtask "kra/pkg/task"
|
||||
)
|
||||
|
||||
// TaskRegistry builds the process-wide registry from dependency-free module
|
||||
// contributions. Dependency-bearing methods are added by their module runtime
|
||||
// constructors after the usecases have been created.
|
||||
func TaskRegistry(catalog module.Catalog) *platformtask.Registry {
|
||||
registry := platformtask.NewRegistry()
|
||||
registry.RegisterAll(catalog.TaskMethods())
|
||||
return registry
|
||||
}
|
||||
|
||||
// RuntimeContributions groups runtime objects that need constructed
|
||||
// dependencies. The binary composition root supplies the concrete modules.
|
||||
type RuntimeContributions struct {
|
||||
Routes []module.RouteRegistrar
|
||||
Tasks []platformtask.Contributor
|
||||
}
|
||||
|
||||
// Runtime activates dependency-bearing tasks and composes module routes.
|
||||
func Runtime(contributions RuntimeContributions, registry *platformtask.Registry) *module.Runtime {
|
||||
platformtask.Apply(registry, contributions.Tasks...)
|
||||
return module.NewRuntime(contributions.Routes...)
|
||||
}
|
||||
Reference in New Issue
Block a user