@@ -33,6 +33,11 @@ type InitFunc = interface{}
3333// e.g., `func(bean)` or `func(bean) error`.
3434type DestroyFunc = interface {}
3535
36+ // BeanSelectorInterface is an interface for selecting beans.
37+ type BeanSelectorInterface interface {
38+ TypeAndName () (reflect.Type , string )
39+ }
40+
3641// BeanSelector is an identifier for a bean.
3742type BeanSelector struct {
3843 Type reflect.Type // Type of the bean
@@ -44,6 +49,11 @@ func BeanSelectorForType[T any]() BeanSelector {
4449 return BeanSelector {Type : reflect .TypeFor [T ]()}
4550}
4651
52+ // TypeAndName returns the type and name of the bean.
53+ func (s BeanSelector ) TypeAndName () (reflect.Type , string ) {
54+ return s .Type , s .Name
55+ }
56+
4757func (s BeanSelector ) String () string {
4858 var sb strings.Builder
4959 sb .WriteString ("{" )
@@ -82,7 +92,7 @@ type CondContext interface {
8292 // Prop retrieves the value of a property from the IoC container.
8393 Prop (key string , def ... string ) string
8494 // Find searches for bean definitions that match the provided BeanSelector.
85- Find (s BeanSelector ) ([]CondBean , error )
95+ Find (s BeanSelectorInterface ) ([]CondBean , error )
8696}
8797
8898// CondFunc is a function type that determines whether a condition is satisfied.
@@ -145,7 +155,7 @@ type BeanRegistration interface {
145155 // SetCondition adds a condition for the bean.
146156 SetCondition (conditions ... Condition )
147157 // SetDependsOn sets the beans that this bean depends on.
148- SetDependsOn (selectors ... BeanSelector )
158+ SetDependsOn (selectors ... BeanSelectorInterface )
149159 // SetExport defines the interfaces to be exported by the bean.
150160 SetExport (exports ... reflect.Type )
151161 // SetConfiguration applies the bean configuration.
@@ -159,12 +169,15 @@ type beanBuilder[T any] struct {
159169 b BeanRegistration
160170}
161171
162- // BeanSelector returns the BeanSelector for the bean.
163- func (d * beanBuilder [T ]) BeanSelector () BeanSelector {
164- return BeanSelector {
165- Name : d .BeanRegistration ().Name (),
166- Type : d .BeanRegistration ().Type (),
167- }
172+ // TypeAndName returns the type and name of the bean.
173+ func (d * beanBuilder [T ]) TypeAndName () (reflect.Type , string ) {
174+ r := d .BeanRegistration ()
175+ return r .Type (), r .Name ()
176+ }
177+
178+ // GetArgValue returns the value of the bean.
179+ func (d * beanBuilder [T ]) GetArgValue (ctx ArgContext , t reflect.Type ) (reflect.Value , error ) {
180+ return d .BeanRegistration ().Value (), nil
168181}
169182
170183// BeanRegistration returns the underlying BeanRegistration instance.
@@ -197,7 +210,7 @@ func (d *beanBuilder[T]) Condition(conditions ...Condition) *T {
197210}
198211
199212// DependsOn sets the beans that this bean depends on.
200- func (d * beanBuilder [T ]) DependsOn (selectors ... BeanSelector ) * T {
213+ func (d * beanBuilder [T ]) DependsOn (selectors ... BeanSelectorInterface ) * T {
201214 d .b .SetDependsOn (selectors ... )
202215 return * (* * T )(unsafe .Pointer (& d ))
203216}
@@ -232,10 +245,6 @@ func NewRegisteredBean(d BeanRegistration) *RegisteredBean {
232245 }
233246}
234247
235- func (r * RegisteredBean ) GetArgValue (ctx ArgContext , t reflect.Type ) (reflect.Value , error ) {
236- return r .BeanRegistration ().Value (), nil
237- }
238-
239248// BeanDefinition represents a bean that has not yet been registered in the IoC container.
240249type BeanDefinition struct {
241250 beanBuilder [BeanDefinition ]
@@ -248,10 +257,6 @@ func NewBeanDefinition(d BeanRegistration) *BeanDefinition {
248257 }
249258}
250259
251- func (r * BeanDefinition ) GetArgValue (ctx ArgContext , t reflect.Type ) (reflect.Value , error ) {
252- return r .BeanRegistration ().Value (), nil
253- }
254-
255260/************************************ ioc ************************************/
256261
257262// Container represents the modifiable aspects of an IoC (Inversion of Control) container.
0 commit comments