Name |
|
---|---|
Backends | JVM JavaScript |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) |
Published | Oct 10, 2019 |
Stats |
Downloads (JVM): 161 Downloads (JS): 33 Source downloads: 150 |
Description |
This is core module, for dependency injection framework Depin. IntroductionWhole concept of this framework, is based on LoggingThis module uses statndard Ceylon logging defined via [[module ceylon.logging]]. Configuration of logging may be altered using Dependency resolutionResolution process is executed via Dependency injection
To use this framework, one first needs to provide dependencies, for further injection.
It is done using Example: dependency String topLevelValue="some value"; dependency Integer topLevelFunction(String someString) => someString.size; Integer topLevelInjection(Integer topLevelFunction(String someString), String topLevelValue){ return topLevelFunction(topLevelValue); } shared void run() { value depedencencyDeclarations=scanner.scan({`package`}); value result=Depin(depedencencyDeclarations).inject(`topLevelInjection`); assert(topLevelValue.size==result); } Scanning Visibility
Dependency visibility and encapsulationIn this release Depin, does not honor Ceylon encapsulation in any way. Whatever is scanned, can be injected. This will be modified in further release. NamingFor some cases it is required to rename given Example: dependency Integer[] summable =[1,2,3]; class DependencyHolder(named("summable") Integer[] numbers){ named("integerSum") dependency Integer? sum = numbers.reduce((Integer partial, Integer element) => partial+element); } void printInjection(Integer? integerSum){ print("Sum of summable is: ``integerSum else "null"``"); } shared void run(){ Depin{ scanner.scan({`package`}); }.inject(`printInjection`); } Warning !It is important to remember that to identify a dependency, it's type, must exactly match with declaration of type in injection.
So in given example Warning 2 !Beacause of https://github.com/eclipse/ceylon/issues/7448 it is not possible to name (using TargetingIn some cases it is required to declare more than one constructor in a class. Example: class TargetedInjection { String constructorName; shared new(){ constructorName="default"; } shared target new targetedConstructor(){ constructorName="targeted"; } shared void printInjection(){ print("Selected construcotr was: ``constructorName``"); } } shared void run(){ Depin{ scanner.scan({`package`}); }.inject(`TargetedInjection.printInjection`); } DecoratorsThis framework uses concept of decorators defined via
More information can be found in specific annotation documentation. HandlersEach decorator can be notified, from outside of framework, it needs just to implement Collectors
Example: dependency Integer one=1; dependency Integer two=2; void assertCollectorInjection(Collector<Integer> namingDoesntMatters){ assert(namingDoesntMatters.collected.containsEvery({one,two})); } shared void run(){ Depin{ scanner.scan({`package`}); }.inject(`assertCollectorInjection`); } |
Dependencies |
ceylon.collection/1.3.3
shared
ceylon.logging/1.3.3
shared
|
Usage |
import herd.depin.core "0.0.2"; |
Module links |
Members Imported By Browse Download .car Download .js Download source archive Download module documentation View API documentation |