Inject

L. Kirven's Avatar

L. Kirven

28 Jun, 2011 03:00 PM

Hi,

I am pretty new to robotlegs. I am trying to inject a RemoteObject into my service. I am patterning my design off of Joel's example on GitHub [ https://github.com/joelhooks/robotlegs-examples-UnionPlatformChatCl... ]. For some reason the injection never happens, so when my service tries to access the remote object. I of course get a 'Cannot access a property or method of a null object reference.' I have verified that I am creating an actual Remote Object and mapped it as such: injector.mapValue(RemoteObject, remoteInst, "ReportViewerSvc"); This injector statement is defined in a command invoked from my own application startup event. I am also using your modules framework if that makes any difference.

Here is a code snippet of my service code:

public class ReportViewerService extends ModuleActor implements IReportViewerService {

    public static const DESTINATION:String = "ReportViewerSvc";

    [Inject(name="ReportViewerSvc")]
    private var dataService:RemoteObject; 

        public function ReportViewerService() {
            super();
        }

}

I appreciate any help that you can provide.

  1. Support Staff 1 Posted by Till Schneidere... on 28 Jun, 2011 03:21 PM

    Till Schneidereit's Avatar

    How are you instantiating your service? If it is mapped as a
    singleton, it should get injected into. If, on the other hand, you're
    creating it manually, you have to either use
    var myService : ReportViewerService = injector.instantiate(ReportViewerService);
    or
    var myService : ReportViewerService = new ReportViewerService();
    injector.injectInto(myService);

  2. 2 Posted by L. Kirven on 28 Jun, 2011 03:26 PM

    L. Kirven's Avatar

    It is mapped as a singleton. Here it is :
    injector.mapSingletonOf(IReportViewerService, ReportViewerService);

  3. Support Staff 3 Posted by Till Schneidere... on 28 Jun, 2011 03:30 PM

    Till Schneidereit's Avatar

    Ah, I didn't look close enough: You have to make the var public for
    the injector to be able to see it. That's a restriction Flash imposes
    which we can't work around.

  4. 4 Posted by L. Kirven on 28 Jun, 2011 03:37 PM

    L. Kirven's Avatar

    Ah, that was it. I should have tried that. Thanks for your help.

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