Inject a Class object as a static variable

Alan Shaw's Avatar

Alan Shaw

05 May, 2010 03:07 PM

Can I make this happen at application startup?:

[Inject] public static var pageClass:Class;

  1. Support Staff 2 Posted by Joel Hooks on 05 May, 2010 03:11 PM

    Joel Hooks's Avatar

    not really. One, I don't think you are going to have luck with the base class injection.

    [inject] public function setPageClass(value:PageClass):void
    {
          pageClass = value; //sets static
    }
    

    That would work.

  2. 3 Posted by Alan Shaw on 05 May, 2010 03:22 PM

    Alan Shaw's Avatar

    Are you saying that it's not possible to inject a variable of type Class (a Class object not an instance)?

  3. Support Staff 4 Posted by Joel Hooks on 05 May, 2010 03:39 PM

    Joel Hooks's Avatar

    It is possible, assuming you only ever have a single mapping for type Class.

  4. Support Staff 5 Posted by Shaun Smith on 05 May, 2010 04:32 PM

    Shaun Smith's Avatar

    Hi Alan,

    Injecting a class (object) into another object is fine and shouldn't give you any issues. Injecting into a class (I'm looking at that "static" keyword) is another story..

    Using a DI container to set static (global) properties, whilst technically possible, is conceptually strange and practically dangerous. Besides, why use mutable statics when you have a DI container at your disposal?

  5. 6 Posted by Alan Shaw on 05 May, 2010 05:16 PM

    Alan Shaw's Avatar

    It appears that I can do this bit of configuration more simply without using injection. Guess I went overboard there. Thanks!

  6. Stray closed this discussion on 11 Feb, 2011 11:42 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