Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unject.StandardKernel;
- import unject.UnjectModule;
- import haxe.rtti.Infos;
- class Demo{
- public static function main()
- {
- var kernel = new StandardKernel([new TestModule()]);
- var samurai = kernel.get(Samurai);
- samurai.attack("the evildoers");
- }
- }
- class TestModule extends UnjectModule
- {
- public override function load()
- {
- bind(Katana).toSelf().withParameter("sharpness", 100);
- bind(Samurai).toSelf();
- bind(IWeapon).to(Sword);
- }
- }
- class Katana implements Infos
- {
- public var sharpness : Int;
- public function new(sharpness : Int)
- {
- this.sharpness = sharpness;
- }
- }
- class Samurai implements Infos
- {
- var weapon : IWeapon;
- public function new(weapon : IWeapon)
- {
- this.weapon = weapon;
- }
- public function attack(target : String)
- {
- return weapon.hit(target);
- }
- }
- class Sword implements IWeapon, implements Infos
- {
- public function new();
- public function hit(target : String)
- {
- return "Chopped " + target + " in half.";
- }
- }
- interface IWeapon
- {
- public function hit(target:String):String;
- }
Add Comment
Please, Sign In to add comment