framework1/framework/gin/hade_context.go

53 lines
1.4 KiB
Go
Raw Normal View History

2024-10-18 14:41:55 +08:00
package gin
import (
"context"
2024-10-18 17:21:19 +08:00
"github.com/Superdanda/hade/framework"
2024-10-23 17:00:42 +08:00
"github.com/Superdanda/hade/framework/contract"
2024-10-18 14:41:55 +08:00
)
func (ctx *Context) BaseContext() context.Context {
return ctx.Request.Context()
}
2024-10-18 17:21:19 +08:00
// Bind engine 实现 container 的绑定封装
func (engine *Engine) Bind(provider framework.ServiceProvider) error {
return engine.container.Bind(provider)
}
// IsBind 关键字凭证是否已经绑定服务提供者
func (engine *Engine) IsBind(key string) bool {
return engine.container.IsBind(key)
}
2024-10-23 17:00:42 +08:00
// GetContainer 获取服务提供者容器
func (engine *Engine) GetContainer() framework.Container {
return engine.container
}
2024-10-18 17:21:19 +08:00
// Make context 实现 container 的几个封装
// 实现 make 的封装
func (ctx *Context) Make(key string) (interface{}, error) {
return ctx.container.Make(key)
}
// MustMake 实现 mustMake 的封装
func (ctx *Context) MustMake(key string) interface{} {
return ctx.container.MustMake(key)
}
2024-10-23 17:00:42 +08:00
// MustMakeLog 快速获取Log服务
func (ctx *Context) MustMakeLog() contract.Log {
return ctx.container.MustMake(contract.LogKey).(contract.Log)
}
2024-10-18 17:21:19 +08:00
// MakeNew 实现 makenew 的封装
func (ctx *Context) MakeNew(key string, params []interface{}) (interface{}, error) {
return ctx.container.MakeNew(key, params)
}
2024-10-19 22:02:19 +08:00
2024-10-23 17:00:42 +08:00
// SetContainer 设置服务提供者容器
2024-10-19 22:02:19 +08:00
func (engine *Engine) SetContainer(container framework.Container) {
engine.container = container
}