https://github.com/johnnyjayjay/guisl
Kotlin EDSL for Guice modules
https://github.com/johnnyjayjay/guisl
Last synced: 4 months ago
JSON representation
Kotlin EDSL for Guice modules
- Host: GitHub
- URL: https://github.com/johnnyjayjay/guisl
- Owner: JohnnyJayJay
- Created: 2019-11-17T21:04:28.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-17T21:04:50.000Z (about 6 years ago)
- Last Synced: 2025-06-03T23:49:39.768Z (7 months ago)
- Language: Kotlin
- Size: 53.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# guisl
Guisl is a small embedded domain specific language for [Guice](https://github.com/google/guice)
modules in Kotlin.
Java equivalents in comments:
```kotlin
module {
// ad hoc MethodInterceptor ("classes" and "methods" are Matchers, by default Matchers.any())
intercept(
classes = subclassesOf(MySuperClass::class.java),
methods = annotatedWith(MyAnnotation::class.java)
) {
it.arguments.forEach(::println)
it.proceed()
}
// more extensions for type and provision listeners available //
bind {
// bindConstant().annotatedWith(Pi.class).to(Math.PI)
constant annotatedWith Pi::class to Math.PI
// bindScope(CustomScope.class, CustomScope.INSTANCE)
scopeAnnotation(CustomScope::class) to CustomScope
// bind(Key.get(ProvidedClass.class))
type(Key.get(ProvidedClass::class))
// bind(OtherProvidedClass.class).annotatedWith(MyAnnotation.class).to(SomeImplementation.class)
type(OtherProvidedClass::class) annotatedWith MyAnnotation::class to SomeImplementation::class
// bind(new TypeLiteral>() {}).to(GenericClassImpl.class)
type(literally>()) to GenericClassImpl::class
scope(CustomScope) {
// bind(String.class).toInstance("foo").in(CustomScope.INSTANCE)
type(String::class) toInstance "foo"
// bind(int.class).annotatedWith(SomeOtherAnnotation.class).toProvider(() -> 42 - 67).in(CustomScope.INSTANCE)
type(Int::class) annotatedWith SomeOtherAnnotation::class toProvider { 42 - 67 }
}
}
}
```