Improve legacy bean support via overrides arg to getBean() #399

Closed
seancorfield opened this Issue Nov 18, 2015 · 3 comments

Comments

Projects
None yet
1 participant
@seancorfield
Member

seancorfield commented Nov 18, 2015

When migrating existing code to FW/1 & DI/1, it would be convenient to be able to tell getBean() "Hey, here are the constructor arguments I want you to use (instead of looking in the factory)!":

var foo = factory.getBean( "foo", { arg1 : 1, arg2 : "two" } );

These could simply be dynamic overrides for the bean being created (augmenting the optional overrides that a bean can be declared with).

This is a very common request and even tho' I nearly always push back and say "That's the wrong way to do it -- use an explicit factory (bean) instead", it actually doesn't look all that difficult to implement (unless I'm missing something obvious that has prevented me from wanted to undertake this in the past!).

@seancorfield seancorfield added this to the 4.0 milestone Nov 18, 2015

@seancorfield seancorfield self-assigned this Nov 18, 2015

seancorfield pushed a commit that referenced this issue Nov 18, 2015

Sean Corfield Sean Corfield
Proof of concept for #399
Pushing this so Dan Switzer can test and see if it solves his use case.
@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Nov 18, 2015

Member

Dan confirmed this is acceptable (although he had a problem with dotted paths... because that's a fussy s.o.b. and I wish I could figure out a completely universal solution!). Will write tests and documentation when I'm back at base.

Member

seancorfield commented Nov 18, 2015

Dan confirmed this is acceptable (although he had a problem with dotted paths... because that's a fussy s.o.b. and I wish I could figure out a completely universal solution!). Will write tests and documentation when I'm back at base.

seancorfield pushed a commit that referenced this issue Nov 19, 2015

Sean Corfield Sean Corfield
Add parent factory constructor arg support #399
Also canonicalize folder names to avoid trailing slash weirdness.
@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Nov 19, 2015

Member

Added constructor argument support to parent getBean() call. This is "safe" insofar as ColdSpring and WireBox will ignore it, but it would be better to trap a non-DI/1 parent and throw an exception (rather than just hiding the fact such parent bean factories might silently ignore the extra arguments -- or worse a custom factory bean may do something wrong if it accepts an extra argument there and we pass it something unexpected).

Member

seancorfield commented Nov 19, 2015

Added constructor argument support to parent getBean() call. This is "safe" insofar as ColdSpring and WireBox will ignore it, but it would be better to trap a non-DI/1 parent and throw an exception (rather than just hiding the fact such parent bean factories might silently ignore the extra arguments -- or worse a custom factory bean may do something wrong if it accepts an extra argument there and we pass it something unexpected).

@seancorfield

This comment has been minimized.

Show comment
Hide comment
@seancorfield

seancorfield Nov 21, 2015

Member

Tests added. Documentation clarified.

Member

seancorfield commented Nov 21, 2015

Tests added. Documentation clarified.

seancorfield added a commit that referenced this issue Jan 12, 2016

Fix bug in #399
Constructor arguments accidentally overwrote metadata!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment