Files
mayfly-go/server/pkg/ioc/component.go

33 lines
498 B
Go
Raw Normal View History

2024-01-21 22:52:20 +08:00
package ioc
import "reflect"
2024-01-21 22:52:20 +08:00
type ComponentOption func(component *Component)
// 组件名
func WithComponentName(name string) ComponentOption {
return func(c *Component) {
c.Name = name
}
}
// 组件
type Component struct {
Name string // 组件名
Type reflect.Type // 组件类型
2024-01-21 22:52:20 +08:00
Value any // 组件实例
}
func NewComponent(val any, opts ...ComponentOption) *Component {
component := &Component{
Value: val,
}
for _, o := range opts {
o(component)
}
return component
}