-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5982257
commit d0a9538
Showing
26 changed files
with
485 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
package dicontainer; | ||
|
||
import java.io.Serial; | ||
|
||
public class DiException | ||
extends RuntimeException | ||
{ | ||
private static final long serialVersionUID = -3019200382390630637L; | ||
@Serial private static final long serialVersionUID = -3019200382390630637L; | ||
|
||
public DiException(String s) | ||
public DiException(String message) | ||
{ | ||
super(s); | ||
super(message); | ||
} | ||
|
||
public DiException(String s, Throwable t) | ||
public DiException(String message, Throwable cause) | ||
{ | ||
super(s, t); | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dicontainer; | ||
|
||
import dicontainer.annotation.Dependency; | ||
|
||
public interface DiResolver | ||
{ | ||
/** | ||
* Resolve all dependencies and construct a new instance of given type using {@link Dependency}. | ||
* @param type type class | ||
* @return new instance | ||
* @throws DiException if type cannot be resolved | ||
*/ | ||
<T> T resolve(Class<T> type); | ||
|
||
/** | ||
* Resolve all dependencies and construct a new instance of given type using {@link Dependency}. | ||
* @param type type class | ||
* @return new instance, or {@code null} if type cannot be resolved. | ||
*/ | ||
default <T> T resolveOrNull(Class<T> type) | ||
{ | ||
try | ||
{ | ||
return resolve(type); | ||
} | ||
catch(DiException ex) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/main/java/dicontainer/dictionary/InstancesDictionary.java
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
src/main/java/dicontainer/dictionary/valuetypes/NullInstanceException.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/main/java/dicontainer/dictionary/valuetypes/Subtype.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/dicontainer/registry/InstancesDictionary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dicontainer.registry; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import dicontainer.registry.valuetypes.Instance; | ||
|
||
class InstancesDictionary | ||
{ | ||
private final Map<Class<?>, Instance<?>> instancesMap = new HashMap<>(); | ||
|
||
<T> void insert(Class<T> type, T instance) | ||
{ | ||
instancesMap.put(type, Instance.of(Objects.requireNonNull(instance))); | ||
} | ||
|
||
boolean contains(Class<?> type) | ||
{ | ||
return instancesMap.containsKey(type); | ||
} | ||
|
||
<T> Instance<T> get(Class<T> type) | ||
{ | ||
return Instance.cast(instancesMap.get(type)); | ||
} | ||
} |
Oops, something went wrong.