Skip to content

Commit

Permalink
Prepare 0.1.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
berberman committed Mar 10, 2022
1 parent 8f8c4e0 commit 1cdce05
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## 0.1.2

* Add `UniqueComponentWrapper` that wraps an object unique-like component

* Create interfaces `IUniqueComponent` and `INamedComonent` with default implementation, in case the
class supposed to be a unique component or named component already has its super class

* Rework generic finding algorithm on `UniqueComponent`

* Fix the bug that property delegate created by `annotatedInjector()`
instantiated `AnnotatedInjector` many times

* Support removing components from scope

## 0.1.1

* Initial release
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "org.mechdancer"
version = "0.1.1"
version = "0.1.2"

repositories { mavenCentral() }
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ package org.mechdancer.dependency
import kotlin.reflect.KClass
import kotlin.reflect.safeCast

/**
* Wraps an object to a component which has a similar implementation to [UniqueComponent]
*
* This class is useful in the case that we can't modify some classes to make them components
*
* Invariance: the implementation in dependency manager and annotation injector enforce
* the invariance on the wrapped type, which means there is no chance to cast an instance
* to its supertype, and you should declare the dependency with the type exactly the same as you
* wrapped and set up in scope.
*/
class UniqueComponentWrapper<T : Any> @PublishedApi internal constructor(
val type: KClass<*>,
val wrapped: T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AnnotatedInjector<T : Any>(private val dependent: T, type: KClass<T>) : Sc
else it.returnType.jvmErasure as KClass<out Component>
) { component ->
(if (needsUnwrap)
// Invariance: See the note on [UniqueComponentWrapper]
(component is UniqueComponentWrapper<*> && it.returnType.jvmErasure ==
component.type)
else
Expand Down Expand Up @@ -69,6 +70,7 @@ class AnnotatedInjector<T : Any>(private val dependent: T, type: KClass<T>) : Sc
else it.returnType.jvmErasure as KClass<out Component>
) { component ->
(if (needsUnwrap)
// Invariance: See the note on [UniqueComponentWrapper]
component is UniqueComponentWrapper<*> && it.returnType.jvmErasure ==
component.type
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ inline fun <reified C : INamedComponent<C>>
* Declare a strict [UniqueComponentWrapper] dependency with type [C] that wrappers type [T],
* creating a delegate that obtains its value
*
* Invariance: See the note on [UniqueComponentWrapper]
*
* @return a property delegate
*/
inline fun <reified C : UniqueComponentWrapper<T>, reified T>
Expand All @@ -173,6 +175,8 @@ inline fun <reified C : UniqueComponentWrapper<T>, reified T>
* Declare a weak [UniqueComponentWrapper] dependency with type [C] that wrappers type [T],
* creating a delegate that obtains its value
*
* Invariance: See the note on [UniqueComponentWrapper]
*
* @return a property delegate
*/
inline fun <reified C : UniqueComponentWrapper<T>, reified T>
Expand Down

0 comments on commit 1cdce05

Please sign in to comment.