map().toValue() doesn't do injectInto

lahmataja.pa4vara's Avatar

lahmataja.pa4vara

03 Feb, 2014 10:18 AM

In most of cases I did something like:

injector.map(Foo).toValue(new Foo("property"));

I also did

var foo:Foo = new Foo("property");
injector.map(Foo).toValue(foo);
injector.injectInto(foo);

So it's 3 lines of code against one. I think, it should be great to have a syntax sugar like

injector.map(Foo).toValue(new Foo("property"), true);

Witch will also do injectInto, this well make config shorter and more readable. What do you think?

  1. 1 Posted by matej on 03 Feb, 2014 11:43 AM

    matej's Avatar

    well :)
    you can always do

    injector.map(Foo).toValue(injector.instantiateUnmapped(Foo));

    or simple

    injector.map(Foo).asSignleton();

  2. 2 Posted by lahmataja.pa4va... on 03 Feb, 2014 12:27 PM

    lahmataja.pa4vara's Avatar

    whell :)
    This is of course possible, but the code of config should be as clean as possible, as I think. Maybe even better solution should be:
    injector.map(Foo).asSignleton(true);
    where true means, that service should be auto initialized even if not injected (for example for events observing).

  3. 3 Posted by matej on 03 Feb, 2014 02:20 PM

    matej's Avatar

    I like that approach :)

  4. 4 Posted by ishaban.flash on 04 Feb, 2014 04:10 PM

    ishaban.flash's Avatar

    I vote for those features, it will be handy imho.

  5. 5 Posted by lahmataja.pa4va... on 04 Feb, 2014 05:33 PM

    lahmataja.pa4vara's Avatar

    The question is, how to implement it in the correct way. Actually all singeltons are created on demand. The question is, how force instance creation as soon, as it's configured.

  6. 6 Posted by ishaban.flash on 26 May, 2014 02:20 PM

    ishaban.flash's Avatar

    Please close topic, because solution implemented in swiftsuspenders 2.2.1.

  7. Support Staff 7 Posted by Shaun Smith on 26 May, 2014 02:26 PM

    Shaun Smith's Avatar

    Cool

  8. Shaun Smith closed this discussion on 26 May, 2014 02:26 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