38 lines
1.6 KiB
Go
38 lines
1.6 KiB
Go
// Package app is the composition root for the running administration service.
|
|
// It knows which business modules are enabled and wires their contributions
|
|
// into the shared platform. Individual modules do not import this package.
|
|
package app
|
|
|
|
import (
|
|
systemrouter "kra/internal/server/router"
|
|
systemworker "kra/internal/worker"
|
|
"kra/pkg/module"
|
|
"kra/pkg/mq"
|
|
platformtask "kra/pkg/task"
|
|
)
|
|
|
|
// Catalog lists the business modules enabled in this binary. Adding an order
|
|
// module means adding one Definition here; system initialization and runtime
|
|
// code consume the catalog without knowing that module's implementation.
|
|
func Catalog() module.Catalog {
|
|
return module.Catalog{Definitions: []module.Definition{Definition()}}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Runtime composes HTTP route contributors from the enabled modules.
|
|
func Runtime(systemRoutes *systemrouter.Routes, systemTasks *systemworker.TaskMethods, registry *platformtask.Registry, catalog module.Catalog, subscriptions mq.SubscriptionRegistrar) (*module.Runtime, error) {
|
|
platformtask.Apply(registry, systemTasks)
|
|
if err := mq.ApplySubscriptions(subscriptions, catalog.SubscriptionContributors()...); err != nil {
|
|
return nil, err
|
|
}
|
|
return module.NewRuntime(systemRoutes), nil
|
|
}
|