Is the Inject metadata really needed

Joe's Avatar

Joe

27 Jun, 2011 07:05 PM

I came across this article from Joel Hooks today, looks like it was written about a year ago and if I am reading it correctly, it looks as if the inject meta tag is not necessary? does this mean I can just use

private var _model:Model = new Model();

instead of

[Inject] public var model:Model;

  1. 2 Posted by Michal Wroblewski on 27 Jun, 2011 08:22 PM

    Michal Wroblewski's Avatar

    Hi Joe,

    You little misunderstood the article. It was about too many different metatags across frameworks, also promoting Robotlegs as a framework that only needs one metatag [Inject]. So to use it correctly always use [Inject] metatag:

    [Inject] public var model:Model;
    

    If you use your first case you always get new Model instance and then no chance to share the same instance in your context.

    Cheers,
    Michal

  2. Support Staff 3 Posted by creynders on 28 Jun, 2011 07:29 AM

    creynders's Avatar

    Actually the inject metadata is not necessary, but obviously you need to inform the injector somehow where injections are needed, therefore you can pass a XML string to the constructor describing all the injection points.
    See "XML configuration of injection points" at
    https://github.com/tschneidereit/SwiftSuspenders/blob/master/README...

  3. Support Staff 4 Posted by creynders on 29 Jun, 2011 08:28 AM

    creynders's Avatar

    Extra note: the example from Joel you're referring to uses constructor injection, w/o inject metadata tags or the XML config of the injections. If SS encounters constructor parameters it automatically injects them with mapped values.

  4. Stray closed this discussion on 21 Jul, 2011 03:24 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