feat: 新增简易版ioc

This commit is contained in:
meilin.huang
2024-01-21 22:52:20 +08:00
parent f4a64b96a9
commit f27d3d200f
106 changed files with 815 additions and 707 deletions

View 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
}