Rethinking Constructor parameters

Martin Fowler marked in his book Refactoring, try to use object as method parameter instead of variable.

Yesterday, after hours of unable making constructor with parameters working in Windsor container, I realized the constructor of my component needs change, using component as parameter, then Castle Windsor container’s auto-wiring just works fine.

To make variable parameter work, as mentioned in this post, I added a #{parameter_name} in to component’s parameter attribute, but I had to add a fake properties section in config file to launch the application, then by sing hastable passing parameter value, the component construct without any problem. The thing is, Windsor is too smart in this case, it always tries auto-wire one of my construct event to a null object. I had to remove the multiple construct method in my component.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s