Dependency injection on child controls

Topics: CAB & Smart Client Software Factory
Oct 7, 2006 at 1:09 AM
originally posted by: clinteastwood

I have an application with many smartparts composed of many child user controls (dynamically created)
I need to inject Services to those user controls, and I think about 2 ways of doing it :
1) the smartparts are injected, and then give the services to their child controls, by constructor, or public property
2) the child controls are considered as smartparts, and so are added to a WorkItem's Items list by their containing smartpart, and thus are injected.

The first way shows, for me, the limit of dependency injection.
I prefer the second way, but I think it could be considered as a kind of hack, and could possibly have performance problems (heavy use of reflection by object builder)

So how to choose between 1 and 2 (or 3 ?)

Oct 7, 2006 at 9:25 PM
originally posted by: MatthiasFG


I would go for solution 2 if you want to use object builder.
And #1 is to me only an option if it's a third party user control which has no dependency/injection attributes in it.

Oct 11, 2006 at 9:07 AM
originally posted by: DamReev

To be honest, in our project we tend to do method 2. I don't consider it to be a hack. I'm actually working on a BuilderStrategy for autoregistering child smartparts.