Name |
|
---|---|
Backends | JVM JavaScript |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) |
Published | Oct 12, 2019 |
Stats |
Downloads (JVM): 107 Downloads (JS): 25 Source downloads: 105 |
Description |
Depin Core - Dependency injection framework core module for Ceylon LoggingThis module uses standard Ceylon logging defined via IntroductionWhole concept of this framework, is based on Dependency resolutionResolution process is executed via Dependency injection
To use this framework, one need to first provide dependencies, for further injection.
It is done using They can be nested in classes and member classes or top level, any formal declaration will be rejected.
The 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.dependencies({`package`}); value result=Depin(depedencencyDeclarations).inject(`topLevelInjection`); assert(topLevelValue.size==result); } Dependency extraction (from 0.1.0)To provide easier interoperation with frameworks where programmer has no control, over creating objects such as Android SDK, Example: class UnaccesibleDependencyContainer(){ suppressWarnings("unusedDeclaration") dependency String name="abc"; } late String name; shared void onCreate(){ value dependencies = scanner.dependencies({`package`}); name = Depin(dependencies).extract<String>(`value name`); assert(name=="abc"); print(name); } Scanning visibilityScanner will scan all classes and they members it doesn't matters either they are shared or not. It may be required to pass scopes which will be excluded in 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.dependencies({`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 !Because 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.dependencies({`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.dependencies({`package`}); }.inject(`assertCollectorInjection`); } } Interoperation with javaBecause of Java type-system definition, where generics are not part of the type declaration, Example: java class in native jvm module public class Generic<T>{ private T data; public Generic(T data){ this.data=data; } public T getData(){ return data; } @Override public String toString(){ return data.toString(); } } dependencies declaration and usage in Ceylon dependency Generic<out Anything> data= Generic("data"); suppressWarnings("uncheckedTypeArguments") shared Generic<String> injection(Generic<out Anything> data){ assert( is Generic<String> data ); return data; } shared void run(){ value dependencies=scanner.dependencies({`package`}); value result=Depin(dependencies).inject(`injection`); assert(result==data); print(result); } |
Dependencies |
ceylon.collection/1.3.3
shared
ceylon.logging/1.3.3
shared
|
Usage |
import herd.depin.core "0.1.0"; |
Module links |
Members Imported By Browse Download .car Download .js Download source archive Download module documentation View API documentation |