Injector metadata

james.hay's Avatar

james.hay

11 Jan, 2010 03:57 PM

Say i have a constructor that requires two parameters. Both are of the same type. I have setup named mappings for two different instances on the injector. How can i specify which named instance is injected into which parameter?

I'm sure i've seen some extra arguments that can be used on the metadata somewhere???

  1. Support Staff 1 Posted by Till Schneidere... on 11 Jan, 2010 04:09 PM

    Till Schneidereit's Avatar

    You can indeed use metadata to specify named mappings for ctor arguments:
    SwiftSuspenders (and I assume you're using the bundled SwiftSuspenders
    injector, right?) supports named method argument injections via the
    "name" parameter to the "Inject" metadata:
    [Inject(name='name1', name='name2',name='')]
    For multiple arguments, you just repeat the "name" parameter for each
    one - they are resolved based on the position in the argument list,
    same as function arguments are generally resolved in AS3.

    Note that you have to put the metadata above the class definition
    instead of above the ctor itself. That's an unfortunate limitation of
    the MXMLC compiler that cannot be worked around.

    For (slightly) more details, please refer to the SwiftSuspenders
    README at http://github.com/tschneidereit/SwiftSuspenders

  2. 2 Posted by james.hay on 11 Jan, 2010 04:12 PM

    james.hay's Avatar

    -----Original Message-----
    From: tschneidereit [mailto:[email blocked]]
    Sent: 11 January 2010 16:10
    To: James Hay
    Subject: Re: Injector metadata [Questions]

    That’s awesome.. thanks. Had solved the named inject problem just not putting the metadata above the class definition. Thanks

    J

  3. Till Schneidereit closed this discussion on 11 Jan, 2010 04:18 PM.

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