Name |
|
---|---|
Backends | JVM JavaScript |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) |
Published | Apr 15, 2020 |
Stats |
Downloads (JVM): 134 Downloads (JS): 22 Source downloads: 133 |
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
From point of view of Depin instantiationTo perform dependency injection Declaration scanningFor this purpose
Scanning visibilityScanner will scan all classes and they members it doesn't matter either they are shared or not and if the packages condained in Dependency provisioningWhen declaration are provided to the Dependency lookupWhenver injection using Dependency resolutionResolution process is executed via Dependency injectionExecuted via
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`); print(result); } Dependency extraction (since 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"; } class Activity(){ late String name; shared void onCreate(){ //Used because can't obtain metamodel reference to local declaration: name value //top level values are obtainable assert(exists nameReference = `class Activity`.getDeclaredMemberDeclaration<ValueDeclaration>("name")); value dependencies = scanner.dependencies({`package`}); name = Depin(dependencies).extract<String>(nameReference); assert(name=="abc"); print(name); } } shared void run(){ Activity().onCreate(); } 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 rename (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`); } } Subtype collector (since 0.2.0)It is sometimes usefull to retreive whole set of object beign subtype of given type. Example: dependency Integer one=1; dependency Integer two=2; dependency String str="abc"; dependency Float float=1.3; void assertSubtypeCollectorInjection(subtype Collector<Object?> namingDoesntMatters){ assert(namingDoesntMatters.collected.containsEvery({one,two,str,float})); } shared void run(){ Depin{ scanner.dependencies({`package`}); }.inject(`assertSubtypeCollectorInjection`); } 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.2.0"; |
Module links |
Members Imported By Browse Download .car Download .js Download source archive Download module documentation View API documentation |