Last active
June 4, 2023 22:40
-
-
Save AxGord/2b65e46fa3dd69e2ef0f6720fa9b6ade to your computer and use it in GitHub Desktop.
Dependency injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.Timer; | |
import pony.Logable; | |
import pony.magic.WR; | |
import pony.magic.DI; | |
// https://github.com/AxGord/Pony/commit/a0c68a0f5d92798b2054fd39dc9e370c0977f2a4 | |
class Main implements DI { | |
@:service private final l: Logable = new Logable('Module:'); | |
@:service private final myService: MyService = new MyService(); | |
@:service private final cat: User = new User('Cat'); | |
@:service private final dog: ModUser = new ModUser('Dog'); | |
// public function destroy(): Void trace('Complete'); | |
private static function main(): Void Main.create(main -> main.destroy()); | |
} | |
class ModUser extends User { | |
@:service private final l: Logable = new Logable('ModModule:'); | |
@:service private final myService: MyService = new MyService(); | |
public function new(name: String) super('$name!'); | |
} | |
class User implements DI { | |
@:service private final myService: MyService; | |
public function new(name: String) myService.print('Hello $name'); | |
} | |
class MyService implements DI implements WR { | |
@:service private final l: Logable; | |
public function new() { | |
Timer.delay(init, 500); | |
} | |
private function init(): Void { | |
l.traceAll(); | |
ready(); | |
} | |
public function print(text: String): Void l.log(text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: