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
Anyone here who can help me with a hexInject problem?
i am trying add numeric values to my injector, and from what i understand from the 2017 summit video i am supose to use "new Dependency" to achive this, but i cant get it to compile.
import hex.di.Injector;
using hex.di.util.InjectorUtil;
class Main extends Sprite {
public static var injector:Injector = new Injector();
...
private function setupScreen():Void{
injector.mapDependency(new Dependency<UInt>(800), "screen.width");
}
....
}
Executing task: lime build flash -debug --connect 6000 <
Source/Main.hx:92: characters 3-68 : Uncaught exception Cannot call null
Source/Main.hx:24: lines 24-129 : Defined in this class
The terminal process terminated with exit code: 1
line 92 is the injector.mapDependency line
line 24 is the class... line
(Using Haxe 4 preview 4, and HexInject 1.0.0-alpha.4)
I have also tried different other combinations:
like:
injector.mapDependencyToValue(new Dependency<UInt>(), WIDTH);
injector.mapDependency(new Dependency<UInt>(),"screen.height").toValue(HEIGHT);
but these give invalid dependency errors:
C:/HaxeToolkit/haxe/lib/hexinject/1,0,0-alpha,4/src/hex/di/util/InjectorUtil.hx:101: characters 3-51 : Called from here
Context.error( "Invalid dependency", clazz.pos );
hm.. it looks like all my trouble has to do with the language server messing up macros and caching them wrong or something, i finally manged to get it working now using
injector.mapDependencyToValue(new Dependency<UInt>(), WIDTH,"screen.width");
injector.mapDependencyToValue(new Dependency<UInt>(), HEIGHT, "screen.height");
Visual code still highlight these lines as problems, but at least now it compiles :)