mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-25 02:20:30 +08:00
feat: 新增简易版ioc
This commit is contained in:
28
server/pkg/ioc/component.go
Normal file
28
server/pkg/ioc/component.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package ioc
|
||||
|
||||
type ComponentOption func(component *Component)
|
||||
|
||||
// 组件名
|
||||
func WithComponentName(name string) ComponentOption {
|
||||
return func(c *Component) {
|
||||
c.Name = name
|
||||
}
|
||||
}
|
||||
|
||||
// 组件
|
||||
type Component struct {
|
||||
Name string // 组件名
|
||||
|
||||
Value any // 组件实例
|
||||
}
|
||||
|
||||
func NewComponent(val any, opts ...ComponentOption) *Component {
|
||||
component := &Component{
|
||||
Value: val,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(component)
|
||||
}
|
||||
return component
|
||||
}
|
||||
Reference in New Issue
Block a user