Mikron is a minimalistic web-free IoC container for dependency injection and externalized configuration management for Java. To use the Maven-based project, you can add the following dependency:
<dependency>
<groupId>net.reevik</groupId>
<artifactId>mikron</artifactId>
<version>${latest}</version>
</dependency>
You will use Mikron annotations to initialize the Mikron context in your Java application. In the following example, we declare a "Mikron Application" by using @ManagedApplication annotation, and instantiate the Mikron context. MikronContext is the implementation of IoC container, where managed instances reside:
@ManagedApplication(packages = {"your.package.to.scan"})
public class Main {
public static void main(String[] args) {
Optional<AnnotatedManagedClass> instance;
try (MikronContext context = MikronContext.init(Main.class)) {
instance = context.getInstance(AnnotatedManagedClass.class.getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Mikron context is the container where the managed instances reside and the dependencies between managed objects get wired. You will use @Managed annotation to declare managed instances:
@Managed
public class ManagedObject {
@Configurable(name = "config.temp")
private Integer temperature;
@Wire
private ManagedDependency managedDependency;
}
and the @Wire annotation introduces dependency injection point whereas @Configurable annotation is used to inject externalized configurations.
You can check out the Mikron Wiki for the documentation and API Docs.
For bugs, questions and discussions please use the GitHub Issues.
Copyright 2024 Erhan Bagdemir
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.