refactor all service dependency injection
This commit is contained in:
32
module/base/initial/service/dependencies.go
Normal file
32
module/base/initial/service/dependencies.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bsm/full/module/base/initial/internal/impl"
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Dependencies contains shared infrastructure supplied by the all module.
|
||||
type Dependencies struct {
|
||||
Redis *redis.RedisClient
|
||||
Etcd *clientv3.Client
|
||||
DB *gorm.DB
|
||||
Cache *cache.Cache
|
||||
}
|
||||
|
||||
func applyDependencies(deps Dependencies) {
|
||||
if deps.Redis != nil {
|
||||
impl.RedisService = deps.Redis
|
||||
}
|
||||
if deps.Etcd != nil {
|
||||
impl.EtcdService = deps.Etcd
|
||||
}
|
||||
if deps.DB != nil {
|
||||
impl.DBService = deps.DB
|
||||
}
|
||||
if deps.Cache != nil {
|
||||
impl.MemorySerice = deps.Cache
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,13 @@ import (
|
||||
)
|
||||
|
||||
type ExposeOptions struct {
|
||||
Dependencies
|
||||
GRPC *grpc.Server
|
||||
Gateway *gwRuntime.ServeMux
|
||||
}
|
||||
|
||||
func Expose(options ExposeOptions) error {
|
||||
applyDependencies(options.Dependencies)
|
||||
server.New(options.GRPC)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user