refactor(core): align with cordis spatiotemporal composability architecture

- Purify core micro-kernel by removing context hardcoded helpers and reverse dependencies
- Eliminate init() side effects in infra plugins with reversible lifecycle disposal
- Completely isolate plugins by removing cross-plugin imports and using core/contracts
- Introduce TaskService and RiskControlService contracts for unified cross-plugin APIs
- Regenerate Swagger documentation and update developer guide matrix
- Achieve 0 violations in check_cordis_architecture.sh and 100% test pass
This commit is contained in:
ryan
2026-08-28 15:05:31 +08:00
parent fc7fae7b0e
commit 299ac30ee4
150 changed files with 4328 additions and 2923 deletions
+18 -2
View File
@@ -7,9 +7,10 @@ package database
import (
"context"
"gorm.io/gorm"
"Wavelet/core"
"Wavelet/core/contracts"
"gorm.io/gorm"
)
// Option configures the database plugin.
@@ -60,7 +61,11 @@ func (p *Plugin) Name() string {
func (p *Plugin) Apply(ctx *core.Context) error {
targetDB := p.db
if targetDB == nil {
targetDB = DB(context.Background())
var err error
targetDB, err = InitDB()
if err != nil {
return err
}
}
svc := &dbServiceImpl{
@@ -68,10 +73,21 @@ func (p *Plugin) Apply(ctx *core.Context) error {
namedDBs: p.namedDBs,
}
if sqlDB, err := targetDB.DB(); err == nil && sqlDB != nil {
ctx.OnDispose(func() error {
return sqlDB.Close()
})
}
core.Provide[contracts.DBService](ctx, svc)
return nil
}
// NewService wraps a GORM DB instance into a contracts.DBService.
func NewService(primary *gorm.DB) contracts.DBService {
return &dbServiceImpl{primary: primary}
}
type dbServiceImpl struct {
primary *gorm.DB
namedDBs map[string]*gorm.DB