Skip to content

Commit

Permalink
# updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sbra0902 committed Oct 26, 2022
1 parent 9a2cede commit 63ee81c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
88 changes: 54 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,18 @@
[![codecov](https://codecov.io/gh/SchwarzIT/kokain/branch/master/graph/badge.svg)](https://codecov.io/gh/SchwarzIT/kokain)
[![jitpack](https://jitpack.io/v/SchwarzIT/kokain.svg)](https://jitpack.io/#SchwarzIT/kokain)

## Kokain
![Kokain Logo](https://raw.githubusercontent.com/schwarzit/kokain/main/kokain-new-martin-268x303.png)

![Kokain Logo](https://raw.githubusercontent.com/schwarzit/kokain/master/android-robot-jonny-full-200x200.png)


## What is Kokain

## Dependency Injection? Why not? It makes things easier, right?

Yes it does! But which Framework strategy is the right for you?

### Code Generation

The Framework generates the injection code as a subclass for every class while compiling. At programing stage the entry point is always a generated shadow class.
No magical things here. Generated code can be viewed. Awesome isn't it?

"Where there is light, there is also shadow"

- there's always a shadow class needed working as proxy between implementation and injection
- error handling in code generation depends on validation in annotation processor
- in java classes they're open per default in kotlin they're not

### More Kotlin based strategy (Property delegates, Extensions)

Kotlin comes along with a lot of features which are very useful. Some DI Frameworks out there provide their service based on these functionalities.
Property delegates combined with some extension methods makes it easy to handle the value of a property in a different place which results in a wonderful api.

"Sounds fancy but are there shadows too?"

- setup instructions are required for every single component which is supposed to be injected by the framework
- it's not possible to inject the activity context


### What's the result if these approaches decide to make a baby?

![Kokain Logo](https://raw.githubusercontent.com/schwarzit/kokain/master/android-robot-jonny-half-200x200.png)
Kokain is pragmatic lightweight dependency injection framework for Kotlin based Applications.
The Framework is reduced to the core functionalities of DI.
Therefore the setup is pretty easy and producing nearly zero overhead.

### Kokain combines code generation with property delegates, that way things become easier



## Features

* easy to use - just annotate beans and start the framework on application start
Expand All @@ -56,7 +28,7 @@ Property delegates combined with some extension methods makes it easy to handle

* pragmatic api

## Features Android
### Features Android only

* inject android context in a lifecycle aware matter

Expand Down Expand Up @@ -168,3 +140,51 @@ class UsageOverview {
}
```

## Testing your code becomes easy like 123

Example based on Mockk

1.) create a simple extension function

```
/**
* Sets up Kokain to use [mock] whenever an object of its type needs to be injected.
*/
inline fun <reified T : Any> Kokain.setMock(mock: T) {
every {
create<T>(any(), T::class)
} returns mock
}
```

2.) do some tests

```
class MySuperFancyControllerTest {
@RelaxedMockK
private lateinit var myBean1: BeanWithCode
@RelaxedMockK
lateinit var kokain: Kokain
@BeforeEach
fun setUp() {
kokain.setMock(myBean1)
KokainInstance.start(kokain)
}
@AfterEach
fun tearDown() {
KokainInstance.stop()
unmockkAll()
}
@Test
fun `do my test magic here without care about kokain`() {
}
```
Binary file added kokain-new-martin-268x303.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 63ee81c

Please sign in to comment.