Injecting into super class and sub class
I just spent several hours debugging injection points on my app. Maybe this should have been obvious? -- it wasn't to me.
So, just for reference -- If you have an base template class and an implementation, and both need to be injected with the same class of dependency, you must use NAMED injection points. Using interfaces isn't enough!
My broken code:
public class AbstractScreenModuleMediator extends ModuleMediator
{
[Inject]
public var screen:IScreen;
...
public class SettingsScreenModuleMediator extends AbstractScreenModuleMediator
{
[Inject]
public var settingsScreen:SettingsScreen;
...
(note: SettingsScreen implements IScreen)
The fix:
public class AbstractScreenModuleMediator extends ModuleMediator
{
[Inject(name="AbstractScreenModuleMediator.screen")]
public var screen:IScreen;
...
public class SettingsScreenModuleMediator extends AbstractScreenModuleMediator
{
[Inject(name="SettingsScreenModuleMediator.settingsScreen")]
public var settingsScreen:XBandScreen;
...
And don't forget to use the name , not the class/interface, in your mapping!
This all seems pretty weak to me -- I don't get why Swift Suspenders wouldn't always use strings as unique keys (package::type.property). but I guess that's a question for another forum...
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Jason Dias on Sep 09, 2010 @ 05:42 PM
Take a look at this thread
http://knowledge.robotlegs.org/discussions/problems/165-mediators-and-inheritance-maximizing-code-reuse-minimizing-hacky-casting
Stray closed this discussion on Feb 10, 2011 @ 05:46 PM.