|
From: Rod J. <rod...@in...> - 2003-09-04 17:51:13
|
All, I've just prototyped another potential BeanFactory feature that tackles the PicoContainer head on. I call it "autowire". Another new optional attribute on <bean>, although it could be supported in non-XML factories as well. Again it's backward compatible. It doesn't complicate the API, although it obviously adds a bit more code to the implementation. I see it working in 3 modes: - autowire="none": the traditional and default behaviour. Dependency checking might be used here if desired. - autowire="byType": if a bean exposes a property of type Foo and there's exactly one bean of type Foo defined in the same factory, the property of type Foo is set to the other bean automatically. My prototype does nothing if there are 0 or >1 beans of type Foo; not sure if this should result in an exception. This is basically PicoContainer behaviour: good for small factories with one object of each type but inadequate for more complex scenarios, which Spring already supports well. - autowire="byName": if a bean exposes a property with name "spouse" it's automatically set to the value of the "spouse" bean in the same factory if one is present. If this results in a type mismatch that's a fatal error. This behaviour has no parallel in PicoContainer but might be useful in some cases. It would work even if there were multiple beans of the type of Spouse. Implementation wasn't very complex. Is this worthwhile behaviour? Should I commit it (probably tomorrow)? Again I think the marketing value is the most important thing. This would enable us to say that we can do anything PicoContainer does, and more. Whether I'd use it myself, I'm not sure. But it wouldn't bother me if I didn't choose to use it. Regards, Rod |