@@ -204,12 +204,16 @@ func (c *container) Configuration(i interface{}) *BeanDefinition {
204204 bValue := reflect .ValueOf (i )
205205 bType := bValue .Type ()
206206
207+ parentBean := c .Accept (NewBean (bValue ))
208+
207209 for j := 0 ; j < bType .NumMethod (); j ++ {
208210 method := bType .Method (j )
209211 if ! strings .HasPrefix (method .Name , "New" ) {
210212 continue
211213 }
212214
215+ var bd * BeanDefinition
216+
213217 switch method .Type .NumOut () {
214218 case 1 : // func(x *T) NewFoo() *Foo
215219 outType := method .Type .Out (0 )
@@ -219,16 +223,15 @@ func (c *container) Configuration(i interface{}) *BeanDefinition {
219223
220224 if outType == bdType {
221225 if method .Type .NumIn () != 1 {
222- panic (fmt .Errorf ("non-parameter constructor required: %s" , method .Type .String ()))
226+ panic (fmt .Errorf ("non-parameter constructor required: %s: %s" , method . Name , method .Type .String ()))
223227 }
224228
225229 bdValues := method .Func .Call ([]reflect.Value {bValue })
226230 bdInst := bdValues [0 ].Interface ()
227- c .Accept (bdInst .(* BeanDefinition ))
231+ bd = c .Accept (bdInst .(* BeanDefinition ))
228232 } else {
229- c .Provide (method .Func .Interface ())
233+ bd = c .Provide (method .Func .Interface ())
230234 }
231-
232235 case 2 :
233236 out0Type := method .Type .Out (0 )
234237 if ! utils .IsBeanType (out0Type ) {
@@ -237,12 +240,12 @@ func (c *container) Configuration(i interface{}) *BeanDefinition {
237240
238241 out1Type := method .Type .Out (1 )
239242 if ! utils .IsErrorType (out1Type ) {
240- panic (fmt .Errorf ("%s: second return type must be error" , method .Type .String ()))
243+ panic (fmt .Errorf ("%s: %s: second return type must be error" , method . Name , method .Type .String ()))
241244 }
242245
243246 if out0Type == bdType {
244247 if method .Type .NumIn () != 1 {
245- panic (fmt .Errorf ("non-parameter constructor required: %s" , method .Type .String ()))
248+ panic (fmt .Errorf ("non-parameter constructor required: %s: %s" , method . Name , method .Type .String ()))
246249 }
247250
248251 bdValues := method .Func .Call ([]reflect.Value {bValue })
@@ -251,16 +254,19 @@ func (c *container) Configuration(i interface{}) *BeanDefinition {
251254 if err , ok := bdErr .(error ); ok && nil != err {
252255 panic (fmt .Errorf ("%s: %w" , method .Type .String (), err ))
253256 }
254- c .Accept (bdInst .(* BeanDefinition ))
257+ bd = c .Accept (bdInst .(* BeanDefinition ))
255258 } else {
256- c .Provide (method .Func .Interface ())
259+ bd = c .Provide (method .Func .Interface ())
257260 }
258261 }
259262
260- // ignore other methods
263+ // 修改注册行号信息为父级bean注册位置
264+ bd .file , bd .line = parentBean .file , parentBean .line
265+ // 依赖父级bean
266+ bd .On (cond .OnBean (parentBean .ID ()))
261267 }
262268
263- return c . Accept ( NewBean ( bValue ))
269+ return parentBean
264270}
265271
266272// Dependencies return the dependency order list in either ascending or descending order.
0 commit comments