Inject non Actor class?
So from reading the book, and some of the discussions on here. It appears I should be able to in my context mapSingleton(MyNonActorClass). Then [Inject] public var nonActorClass:MyNonActorClass?
Is this correct? When I do this the contractor never gets called on MyNonActorClass, therefore when I tried to use this the Inject never happened so the object is null.
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
1 Posted by Stray on 09 Sep, 2011 10:59 PM
Hi Jason,
yes, that should work - as long as the class where the [Inject]... code is will be created using the injector.
What kind of class are you injecting into? And how does that class get created? If you just do
new Thing()
The injector won't have had a chance to process that class to give it the injections.
I suspect this is the cause of the problem.
Stray
2 Posted by Jason Graham on 09 Sep, 2011 11:15 PM
Here is what I have.
My application has it's Context class which calls in the onRegister method
injector.mapSingleton(EntryDataService);
//map service
injector.mapSingletonOf(IApprovalService,ApprovalService);
EntryDataService is an existing class we have that extends the Flex DataService class which we want to avoid wrapping this class in an Actor if possible.
When ApprovalService gets called via the ApprovalCommand class which is also mapped in the onRegister.
ApprovalService has the following.
[Inject]
public var entryDataService:EntryDataService;
When the ApprovalCommand calls the method getApproval() the entryDataService is null, so I put a breakpoint in the constructor of EntryDataService never getting instantiated.
3 Posted by Stray on 09 Sep, 2011 11:21 PM
Hi Jason,
There are only a limited number of reasons why this could happen - either your injection point is broken and actually is private, 'Inject' is misspelled or something similar, or your metadata is being stripped out.
As the ApprovalService is being injected into the Command ok, we can pretty much rule out the metadata problem.
If your injection wasn't mapped properly then you'd get an injector error. So, most likely your [Inject] tag is broken.
Check through the common problems document (link is on the right on the front page of the forum) for a list of things to look out for.
If you wan't to paste the actual code in then that could be useful.
Stray
Support Staff 4 Posted by Ondina D.F. on 02 Nov, 2011 05:01 PM
Jason,
Feel free to reopen this discussion in case you have more questions or you need further assistance with this issue. Please open new threads for new issues.
Ondina
Ondina D.F. closed this discussion on 02 Nov, 2011 05:01 PM.