Jesus H... so to use the [Inject] tag, I have to utilize one of those injector methods for it in the Context class?
Jesus H... so to use the [Inject] tag, I have to utilize one of those injector methods for it in the Context class?
You can map the injector anyplace where the IInjector is available (by default the context or a command)
Thanks Joel - not sure I'll definitely use it that way but it opens up possibilities...Why do you say it would be naughty Shaun?
If the state pattern is mostly about using different concrete classes of the same interface to implement logic instead of a bunch of 'if / else' statements... why is it naughty to achieve the same thing via switching the injector mapping instead?
It may well be naughty - but I'm intrigued as to why you think it is... can't state/command breed? (You may know this path leads to pain... !)
Something has to know about it, so what do you think would be a better
place for that? And as Stray said: Your context only does the mapping,
it doesn't have to do the creating.
> 2. Not using Inject, I could just write 1 line of code instantiating my
> instance, and going on about my day.
How do you get access to a singleton instance of a shared service in
your command without DI or some boiler-plate?
If your answer is "by using MyService.getInstance", then: How do you
get access to a singleton instance of a shared service typed as an
interface? If you don't need that, I guess you don't need DI here.
> I get mapping Commands & Mediator's using DI. I don't get mapping Services,
> DisplayObject instances for the Mediator, or anything else at all... makes
> no sense, I see no value. Seems totally un-encapsulated.
In mediators, it's really the only way to set the mediated view with
its' concrete class (or as an interface you want it to be injected as)
without forcing you to cast it.
> I've seen some implementations of Prana and SpringAS that basically allow
> you to swap your Interface injections with mock-implementations for either
> testing with fake data while your back-end is being developed. But I'm not
> doing that here. It seems like this DI stuff is being used just to use it.
I'm doing exactly that quite often and I love that I can switch
between implementations by changing just one line in my injector
mappings without having to do a lot of plumbing.
And that's exactly the tremendous value of DI: It lets you built very
complex interrelated object trees that share exactly the amount of
knowledge they have to without having to write lots of boiler-plate
code for it.
Ok, going to bed now.
cheers,
till
It seems like this DI stuff is being used just to use it. I don't get it...
The Context has knowledge of how a Service is created. It shouldn't have to have all of this knowledge.
Not using Inject, I could just write 1 line of code instantiating my instance, and going on about my day.
1. That sounds like a great optimization technique... AFTER you're done, not ahead of time. In small projects sure... but seriously? I just don't see my brain cells being used to "think about which class I can possibly inject to save a few lines of code".
2. Right, but no one does that. They say they do, but they don't. I agree with having it for those who will use it, but it's like 10% of the market.
1. Yeah, but now the class is in 2 places vs. 1. How does the Context even "know" it's going to be used? Seems way too coupled.
2. You're right, I don't need an interface, so Singleton.instance it is.I think the problem here regarding Mediator's is when you all say "Mediator", I hear "Presenter". So, what I always did in PureMVC was:new MyMediator(myViewInstance)And the constructor was:public class MyMediator(myView:MyView):void{super(NAME);this.myView = myView;}A Mediator never uses any other View, so this concrete implementation is fine. Those who try to give me some interface View in the constructor for testing bs are space cadets. So, I'm not casting it; I get a reference to my View, which I know what it'll be, and go on about my day.
...regarding that you use it... oh.... *sigh* Majority of code I see is never even close to that testable, let alone having enough developers capable enough to go down that road, and even if they did, you'd have a hard time selling on the value of writing the same class twice.
Yes, but you imply you already knew you were going to. I get what you're saying, but I fail to see how that works with Enterprise code bases. Those grow, they aren't architected from the start. I'm saying it's impossible to know, yet you're saying you can know.
Secondly, you've clearly stated you're using unit testing and TDD. What if you're not doing any of those things? Assuming so, do any of my arguments still seem sound?
This is exactly what the InjectorContext I'm working on for SP is for. I find it pretty funny that it's a solution to the injection problem known as "robot legs", and the catalyst for getting me off my arse to write it is Robot Legs (the framework).
I guess I'm easily amused ;-)
I still don't follow the static / dynamic tracking difference though - as far as the class using an interface API is concerned as long as it looks, talks and walks like IDuck it's an IDuck surely? Or do you mean for testing / debugging?
I was just thinking that you could have very simple command that effectively remapped the state in a few different areas by changing the injector mappings.
That said - I guess an API switch is more polite :)
I think the possibilities of using remapping during the dev phases, or for testing, are really interesting though.
Ah... I just meant that the object itself should probably have an API
function that can act as a switch as in "setStatusTo()" or whatever,
rather than me effectively reaching inside it by remapping the
injection...
Or - thinking more - I guess the various objects can each listen
individually and do their own switching triggered by the same event.
Which I guess is what you were suggesting - to avoid one command
having knowledge of which various parts of the system all need to be
changed.
Thanks for wrestling this one with me!
Testing has it's place to be sure. Building reusable libraries for release is different and unit tests are justifiable. They're a value-add to the project and guarantee stability and peace of mind.
Sometimes I hear someone excitedly share that their tests found a bug and I just want to push their chair to the side and run the application in debug mode. "Look, see, I found the bug just as easily without all of those hours writing tests".
Sorry, just catching up, and I know this is not the list to share but here goes.
I'm with Jesse on unit testing. I've never really appreciated the value of unit tests in application development, especially when you're doing a lot of refactoring in a large system.
Maintaining unit tests in an enterprise system means that there are twice as many classes to update with every refactor.
Because of type-checking, debugging and all the other features of Flex Builder I've never had a problem finding and fixing bugs quickly.
I think a lot of developers could learn better debugging techniques in place of building and maintaining a test suite for a GUI-strong enterprise application.
Proper architecture, separation of responsibilities and encapsulation are essential to minimizing the scope of your changes, and as a result your testing and bugs.
I've never been up at 3am fixing bugs I wished were found by unit tests, which I would have to write and update with each change in the system. A portion of all the time I save by not writing unit tests is applied to testing changes in the application manually (which I understand is still an essential exercise even with a test suite). Sometimes I hear someone excitedly share that their tests found a bug and I just want to push their chair to the side and run the application in debug mode. "Look, see, I found the bug just as easily without all of those hours writing tests".
Testing has it's place to be sure. Building reusable libraries for release is different and unit tests are justifiable.
They're a value-add to the project and guarantee stability and peace of mind.
TDD can help you design your API well and forces you to use your library.
Wherever you release documentation of code (such as an OS project) unit testing would be appropriate.
But if I ever see a unit test targeting an application-specific MXML component I'd delete it promptly.
I'll admit I may be ignorant, maybe I haven't given testing a long enough trial.
Sorry, just catching up, and I know this is not the list to share but here goes.What? This is the sharing-is-caring list! (aside from my little rant the other night, apologies all, and a special apology to Jesse! sorry dude).
I don't see a hell-of-a-lot of value in unit testing the wiring of an application - which, generally speaking, is where a large portion of time is spent when building Flex/Flash apps: building composite view components, layout, message passing, wiring views to models etc.