Skip to content

An dependency injection container for the Java language

License

Notifications You must be signed in to change notification settings

Paulomart/ioc.java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ioc.java

Minimalistic IOC container for Java applications

Usage

Maven Repository

Add the following maven repository to your pom:

<repository>
  <id>paul-h.de_repo</id>
  <url>https://mvn.paul-h.de/</url>
</repository>

Include the project as dependency:

<dependency>
  <groupId>de.paulomart</groupId>
  <artifactId>ioc</artifactId>
  <version>3.0.0</version>
</dependency>

Example

@startuml

hide empty members

class Foo implements InterfaceA {
}

class Bar implements InterfaceB {
}

@enduml
// create a instance of the container
Container container = new Container();

container.registerTransient(Foo.class);
container.registerSingeltion(Bar.class);


// resolves new instance everytime
InterfaceA a1 = container.resolve(InterfaceA.class);
InterfaceA a2 = container.resolve(InterfaceA.class);
// => a1 != a2

// resolves to the same instance everytime
InterfaceB b1 = container.resolve(InterfaceB.class);
InterfaceB b2 = container.resolve(InterfaceB.class);
// => b1 == b2

For a more detailed example see the src/examples/java folder.

About

An dependency injection container for the Java language

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published