FactoryFX
Lightweight dependency and data (re-)injection framework for all kinds of Java applications.
Introduction
-
Lightweight
Fully debuggable programmatic Java API (no annotations)
Fast startup (no classpath scanning) -
Dependency injection
Factory based implementation of the dependency injection pattern. -
Data (re-)injection
(Like dependencies) Data can be injected into Java objects.
Supports OOP and avoids OR mapping or external configuration files.
Allows optimized (partial) reconfiguration at runtime.
Key concepts
- Key concepts
Why use FactoryFX?
Setup
Group ID | Artifact ID | Version |
---|---|---|
io.github.factoryfx | factory | 2.1.0 |
java 16+ required
Dependencies
Gradle example dependency setups
New project template
Changelog
Basic example “Hello World”
Factory
public class PrinterFactory extends SimpleFactoryBase<Printer,PrinterFactory> {
public final StringAttribute text = new StringAttribute();
@Override
protected Printer create() {
return new Printer(text.get());
}
}
Live object
public class Printer{
private final String text;
public Printer(String text) {
this.text = text;
}
public void print(){
System.out.println(text);
}
}
Setup the dependency tree
new FactoryTreeBuilder<Printer,PrinterFactory,Void>(PrinterFactory.class)
.addSingleton(PrinterFactory.class, ctx-> {
PrinterFactory printerFactory = new PrinterFactory();
printerFactory.text.set("Hello World");
return printerFactory;
})
.microservice().build().start().print();
The complete example
Documentation
Fundamentals
- Dependency injection
Injecting a dependency into a live object - Data injection
Injection data into a live object - Factory
Explanation of factories - Liveobject
Explanation of live objects - initializr
Code generator for initial project setup
Common applications
- REST server
Basic jetty server with a jersey REST resource
Advanced
- Comparison
Comparison to other frameworks - Lifecycle
Lifecycle configuration (start/stop/update) - Migration
Configuration data migration - Persistent storage
Persistent configuration data storage using a database - Polymorphism
Polymorphic factories - Runtime status
Passing runtime status across configuration updates (e.g request counter) - Update
Optimize factory update/server restart e.g. for live objects whose initialization is very time-consuming - Monitoring
Request monitoring data - Permissions
Permissions on attribute level - Custom configuration REST API
(Re-)configuration over a custom REST API - Configuration data
How to handle configuration data - Runtime configuration change
Different ways to change the configuration at runtime - Configuration via web application
Configuration via web application - Reuse Factories in mutiple projects
Factory with generic RootFactory - Encrypted attributes
Hiding information from the client like passwords
Example
Example
An example that implements a simplified online store.
License
Released under the Apache 2.0 license.
Professional support
FactoryFX is the long-time development effort of the german company SCOOP Software GmbH. We are a consulting and software company with a constant direction towards state-of-the-art technologies and methods. Our high performance systems are used in multiple medium sized and large enterprises in branches such as online retail, telecommunications, financial services, logistics and local government.
If you are thinking about using FactoryFX in your own project and need more help, SCOOP Software is willing to offer professional support on a commercial basis. We offer workshops, coaching, or any other help to get your FactoryFx project up and running.