injector

Light library to implement DI (dependency injection) pattern for JavaScript platform.
https://bitbucket.org/yar3333/haxe-injector

To install, run:

haxelib install injector 1.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

injector haxe library

Light library to implement DI (dependency injection) pattern. Library use haxe RTTI to get information about types (macro-related stuff not used).

Compared to other haxe DI libraries:

* simple design with minimal magic (only RTTI);
* no macro, so library may be used without haxe (just emulate RTTI data for class in your native code);
* ready to separated compilation on JavaScript target (useful for using with `webpack` and similar);
* only classes and interfaces are supported.

Basic using

@:rtti
class MyClass
{
	@inject var myService : Service;

	public function new() {}
	
	public function myFunc()
	{
		trace("myFunc");
		service.serviceFunc();
	}
	
	// below method is only need if you use separate compilation (nmp modules, for example)
	// because Type.getClass() can't get data across js module boundary
	public function getClass() return Type.getClass(this);
}

@:rtti
class Service
{
	public function new() {}
	
	public function testFunc()
	{
		trace("testFunc!!!");
	}
}

class Main
{
	public static function main()
	{
		var injector = new Injector();
		injector.map(Service, new Service());
		
		var myObj = new MyClass();
		injector.injectInto(myObj);
		
		myObj.myFunc();
	}
}
Contributors
yar3333
Version
1.0.0
Published
2 weeks ago
License
LGPL

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github