-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## | `Lithe DI - Add as depend:` | ||
Here is how to add this framework depending on your project. | ||
### | `Gradle`: | ||
If you use Gradle with Groovy, then here is an example of adding dependencies: | ||
```groovy | ||
repositories { | ||
// other repositories | ||
maven { | ||
name = "clojars.org" | ||
url = uri("https://repo.clojars.org") | ||
} | ||
} | ||
dependencies { | ||
// other depends | ||
implementation 'works.naifu:lithe:2.1.1' | ||
} | ||
``` | ||
|
||
### | `Maven`: | ||
|
||
Repository: | ||
|
||
```xml | ||
<repository> | ||
<id>clojars.org</id> | ||
<url>https://repo.clojars.org</url> | ||
</repository> | ||
``` | ||
|
||
Depend: | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>works.naifu</groupId> | ||
<artifactId>lithe</artifactId> | ||
<version>2.1.1</version> | ||
</dependency> | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: suuft | ||
custom: https://www.buymeacoffee.com/suuft |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## | `Lithe DI - Usage:` | ||
*You can found full example-code in:* [LINK](https://github.com/suuft/Lithe/tree/master/src/test/java/net/lithe/test) | ||
|
||
First, lets create an application class that ll run the JVM. E.i. - Main: | ||
```java | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
} | ||
} | ||
``` | ||
Lets create an abstract class (an interface, but you can create abstract class or a simple class) that ll have abstract methods for working with some data. I have this as metric, so this class ll count the number of sessions: | ||
```java | ||
public interface SessionCounter { | ||
int getSessions(); | ||
void incrementSessions(); | ||
} | ||
``` | ||
Okay come write it s implementation: | ||
```java | ||
public class MySessionCounter implements SessionCounter { | ||
|
||
private int sessions; | ||
|
||
@Override | ||
public int getSessions() { | ||
return sessions; | ||
} | ||
|
||
@Override | ||
public void incrementSessions() { | ||
sessions++; | ||
} | ||
} | ||
``` | ||
Good job! You should write a class that register dependencies, for further using - Adept, it will extends from `SimpleAdept`: | ||
```java | ||
public class CounterAdept extends SimpleAdept { | ||
@Override | ||
public void install() { | ||
register(SessionCounter.class, MySessionCounter.class); | ||
} | ||
} | ||
``` | ||
Done! So you can create an injector through the `Lithe` class and use the registered dependencies. I wrote an example in the Main class. | ||
```java | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Injector injector = Lithe.createInjector(new CounterAdept()); | ||
System.out.println("Current sessions: " + injector.getInstance(SessionCounter.class).getSessions()); | ||
|
||
System.out.println("Try increment #1"); | ||
injector.getInstance(SessionCounter.class).incrementSessions(); | ||
|
||
System.out.println("Try increment #2"); | ||
injector.getInstance(SessionCounter.class).incrementSessions(); | ||
|
||
System.out.println("Current sessions: " + injector.getInstance(SessionCounter.class).getSessions()); | ||
} | ||
} | ||
``` | ||
The final output will show us the number 2. So you did everything right. Cool! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## | `Lithe DI - Learn project` | ||
Hi! This is a learn project, if you have idea or know how to refactor the code, be sure to send me pull requests, issues. Im not adequate criticism. | ||
### | `Road-Map`: | ||
1) Add Automatic-Generation adept. | ||
2) Add Auto-Injection Depends. | ||
3) Refactor all. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Valeriy Shushpanov (suuft) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## | `Lithe DI` | ||
A small & fast but convenient framework for working with dependencies. I'll add dependency injection soon. | ||
|
||
### | `Links`: | ||
* [About this learn project](https://github.com/suuft/Lithe/blob/master/LEARN.md) | ||
* [Add as Depend](https://github.com/suuft/Lithe/blob/master/.github/DEPEND.md) | ||
* [Usage Example](https://github.com/suuft/Lithe/blob/master/.github/USAGE.md) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
group 'net.wonsi' | ||
version '1.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |