2

In app config file I have a Signal/Command mapping

signalCommandMap.map(DisconnectUserSignal).toCommand(DisconnectUserCommand);

Then, I have two connection classes:

public class BaseConnection implements IBaseConnection
{ 
   // When I am trying to inject the signal here: 
   [Inject] public var disconnectUserSignal:DisconnectUserSignal; // it is always null

   _netConnection = new NetConnection();
   ... 
}

and

public class BBConnection extends DefaultConnectionCallback implements IBBConnection
{ 
  // When I am trying to inject the signal here:
  [Inject] public var disconnectUserSignal:DisconnectUserSignal; // it works perfectly fine

  _baseConnection = new BaseConnection(this);
}

Is there any suggestion of what might be the reason? Thank you

inside
  • 3,047
  • 10
  • 49
  • 75
  • did you map the signals itself in the injector? like _injector.map( DisconnectUserSignal ).asSingleton();_ – fsbmain May 16 '14 at 15:23
  • I haven't but will do now and let you know the result. – inside May 16 '14 at 15:25
  • and how do you create the _BaseConnection_, it should be via the _robotlegs_ as well, e.g. _injector.getInstance(BaseConnection)_ and of course you should map it before too – fsbmain May 16 '14 at 15:31
  • I've never done that not with BBConnection neither with BaseConnection, however Signal in BBConnection is being injected properly, but I can give it a try, so do I use injector.getInstance(BaseConnection) inside the AppConfig file? – inside May 16 '14 at 15:34
  • you should use it whenever you need a reference to the _BaseConnection_ object, all objects that has _[Inject]_ metatag should be created via _injector.getInstance_ otherwise how robotlegs will inject the properties ) – fsbmain May 16 '14 at 15:37
  • I'm having the same problem here but I think your "solution" is more of a workaround than an actual solution. It doesn't explain why the dependency injection of the signal doesn't work, and it doesn't make it work. It just finds another way of achieving what you need. But I'd really like for the dependency injection to actually work, because I really need a reference to the signal that is responsible for the creation of this command. – Gareth Sep 21 '18 at 19:33

1 Answers1

0

After going through the robotlegs framework documentation - I found the answer:

I changed the _baseConnection to be an interface, and moved everything from BaseConnection's constructor into init method and now I am injecting it inside my BBConnection.

Here how BBConnection looks now:

[Inject]
public var baseConnection:IBaseConnection;

public function BBConnection() 
{
}

[PostConstruct]
public function init():void
{
   baseConnection.init(this);
}

Now I can successfully inject Disconnect signal inside base connection.

Source: https://github.com/robotlegs/robotlegs-framework/wiki/common-problems#injected-properties-are-null-in-constructor

inside
  • 3,047
  • 10
  • 49
  • 75