@@ -25,13 +25,23 @@ import (
2525 "github.com/go-spring/spring-core/conf"
2626)
2727
28- // InitFunc defines the prototype for initialization functions,
28+ // BeanInitFunc defines the prototype for initialization functions,
2929// e.g., `func(bean)` or `func(bean) error`.
30- type InitFunc = interface {}
30+ type BeanInitFunc = interface {}
3131
32- // DestroyFunc defines the prototype for destroy functions,
32+ // BeanDestroyFunc defines the prototype for destroy functions,
3333// e.g., `func(bean)` or `func(bean) error`.
34- type DestroyFunc = interface {}
34+ type BeanDestroyFunc = interface {}
35+
36+ // BeanInitInterface defines an interface for bean initialization.
37+ type BeanInitInterface interface {
38+ OnBeanInit (ctx Context ) error
39+ }
40+
41+ // BeanDestroyInterface defines an interface for bean destruction.
42+ type BeanDestroyInterface interface {
43+ OnBeanDestroy ()
44+ }
3545
3646// BeanSelectorInterface is an interface for selecting beans.
3747type BeanSelectorInterface interface {
@@ -149,9 +159,9 @@ type BeanRegistration interface {
149159 // SetName sets the name of the bean.
150160 SetName (name string )
151161 // SetInit sets the initialization function for the bean.
152- SetInit (fn InitFunc )
162+ SetInit (fn BeanInitFunc )
153163 // SetDestroy sets the destruction function for the bean.
154- SetDestroy (fn DestroyFunc )
164+ SetDestroy (fn BeanDestroyFunc )
155165 // SetCondition adds a condition for the bean.
156166 SetCondition (conditions ... Condition )
157167 // SetDependsOn sets the beans that this bean depends on.
@@ -192,13 +202,13 @@ func (d *beanBuilder[T]) Name(name string) *T {
192202}
193203
194204// Init sets the initialization function for the bean.
195- func (d * beanBuilder [T ]) Init (fn InitFunc ) * T {
205+ func (d * beanBuilder [T ]) Init (fn BeanInitFunc ) * T {
196206 d .b .SetInit (fn )
197207 return * (* * T )(unsafe .Pointer (& d ))
198208}
199209
200210// Destroy sets the destruction function for the bean.
201- func (d * beanBuilder [T ]) Destroy (fn DestroyFunc ) * T {
211+ func (d * beanBuilder [T ]) Destroy (fn BeanDestroyFunc ) * T {
202212 d .b .SetDestroy (fn )
203213 return * (* * T )(unsafe .Pointer (& d ))
204214}
0 commit comments