//where you're creating the mappings
injector.mapClassNameToValue("Void->Void", model.someFunction);
//and in the view
@Inject
public var someFunction:Void->Void;
Object { _inputs: Array[0] }
) it worked before my changes :( please take a look.
I'm continue trying some things with hexMachina and I inject controller to my view:
@Inject
public var controller:IGeneratorController;
When I tried in module insert the view into injector like following, it didn't worked:
this.getInjector().mapToValue(ITransferView, transferView);
But this working:
this.getInjector().injectInto(transferView);
what injectInto do?
And also, I should to "attach" to view into the module (i.e "mapToValue") and not the module to view (i.e "injectInto"), I'm afraid that I not exactly understand the "Injector" thing...
IInjectorContainer
get an injector
object, but it's empty, so in the module I should "share" the module's injector with view's injector by this.getInjector().injectInto(transferView);
, but if I want add something to module injector I just need to "map it in" by this.getInjector().map methods
or by this._map etc...
// code:
injector.map(ClassX).toValue(x);
// english:
// every time when something requires ClassX provide it this specific value x ... aka singleton pattern
//-----
// code:
injector.map(ClassX).toType(ClassX);
// english:
// every time when something requires ClassX create a new instance of ClassX and provide that instance ... aka factory pattern
injector.injectInto(instance)
does following... it takes the instance you're passing in and goes through all the pre-reflected data (generated by the IInjectorContainer described above) and does injector.getInstance(_whatever type is the public variable type_)
which returns instances based on the mapping (or rules in other words) described above
this._map
is just a shortcut for this._injector.map
this._map(ILoginModel, LoginModel, '', true);
) so when I'm doing _get (i.e: this._get(ILoginModel)
) I'm getting a new instance of LoginModel
? (lol when I'm writing this it's makes more sense)
class Main extends App {
static function main() {
new Main();
}
override function init() {
super.init();
var injector = new Injector();
var vo = new VO();
vo.val = 'bar';
injector.map(VO).toValue(vo);
var container = new Container();
injector.injectInto(container);
}
}
class VO {
public var val = 'foo';
public function new() {
}
}
class Container implements hex.di.IInjectorContainer {
@inject
var _vo:VO;
public function new() {
}
@PostConstruct
public function enter() {
trace("vo.val:" + _vo.val);
}
}
Uncaught TypeError: Cannot read property 'val' of undefined
Uncaught TypeError: mapping.getResult is not a function
import hex.di.Injector;
class Main {
static function main() {
new Main();
}
function new() {
var injector = new Injector();
var vo = new VO();
vo.val = 'bar';
injector.map(VO).toValue(vo);
var container = new Container();
injector.injectInto(container);
}
}
class Container implements hex.di.IInjectorContainer {
@Inject
var _vo:VO;
public function new() {
}
@PostConstruct
public function enter() {
trace("vo.val:" + _vo.val);
}
}
build.hxml-cp src
-main Main
-lib hexdsl
-js main.js
vo.val:bar