What is FxContainer?
FxContainer is the only IoC container that is built using JavaFX and specifically meant for JavaFX applications to provide Dependency Injection.
It is open source (Apache License). You can use it in your JavaFX applications, extend it, redistribute it, OEM it - pretty much anything you want.
The world is already filled with dozens of IoC containers. Do we need another one? That is the question I pondered a lot before setting out to write a DI/IoC container in JavaFX.
An analysis of Spring and Guice - two of the popular DI frameworks, and how to apply them successfully with JavaFX reveals the following:
- Spring supports XML and Annotation based Dependency Injection.
- Guice supports Annotation and binding & provider API based DI.
- Both support Constructor and Setter Injection.
- Unfortunately, JavaFX does not support Annotations.
- JavaFX also does not support constructor injection.
- Setter injection feels artificial for JavaFX programming style
- Setter Injection introduces atleast one known side effect that can cause certain type of JavaFX objects not to work correctly. For instance, CustomNode create() functions that depend on objects injected by setter injection fail
- A minimal Spring DI requires 3-4 jars that can add up and exceed 1 MB. This is okay for server side applications. But this can be a overhead for medium sized client side JavaFX applications that are not regularly used (and hence not cached)
- No IoC container supports "sequence" - JavaFX's very own version of collection.(understandably so)
- It is 75K in size.
- No more awkward setters (awkard in the context of JavaFX that is). Uses Init Injection - the style that is natural to JavaFX language.
- Uses xml for DI configuration. In fact the xml is very much like Spring. You will feel very much at home if you know Spring
- Supports sequence, list, set, map
- Mix and match Java and JavaFX objects during wiring as needed.?
- Project Website: https://fxobjects.dev.java.net
- Download: https://fxobjects.dev.java.net/files/documents/11182/152368/fxcontainer-1.0.zip
- Get Started in 10 minutes: http://www.slideshare.net/skshenoy/javafx-dependency-injection-with-fxcontainer