refactor all service dependency injection
This commit is contained in:
@@ -2,26 +2,25 @@ package impl
|
||||
|
||||
import (
|
||||
"bsm/full/module/base/mgt/internal/config"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
"git.apinb.com/bsm-sdk/core/with"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
RedisService *redis.RedisClient // Redis 客户端服务
|
||||
EtcdService *clientv3.Client // Etcd 客户端服务
|
||||
MemorySerice *cache.Cache // 内存缓存服务
|
||||
RedisService *redis.RedisClient
|
||||
EtcdService *clientv3.Client
|
||||
MemorySerice *cache.Cache
|
||||
DBService *gorm.DB
|
||||
)
|
||||
|
||||
// NewImpl 初始化各类服务实例
|
||||
// NewImpl initializes infrastructure for standalone execution.
|
||||
func NewImpl() {
|
||||
// 初始化内存缓存
|
||||
MemorySerice = with.Memory(nil)
|
||||
// 初始化 Redis 缓存
|
||||
RedisService = with.RedisCache(config.Spec.Cache)
|
||||
// 初始化数据库服务
|
||||
WithDatabases(config.Spec.Databases, nil)
|
||||
// 初始化 Etcd 服务
|
||||
EtcdService = with.Etcd(config.Spec.Etcd)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package impl
|
||||
|
||||
import (
|
||||
"bsm/full/module/base/mgt/internal/models"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
coreTypes "git.apinb.com/bsm-sdk/core/types"
|
||||
@@ -21,5 +22,6 @@ func WithDatabases(cfg *conf.DBConf, opts *coreTypes.SqlOptions) {
|
||||
printer.Error("Database Init Failed !")
|
||||
panic(err)
|
||||
}
|
||||
DBService = models.DBService
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user