SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
JavaFX Dependency
Injection with
FxContainer

                    Presented by
                 Srikanth Shenoy
                    ObjectSource
  Learn FxContainer in 10 minutes
Introduction
   Who am I?
       A hands-on architect
       Experienced and very knowledgeable in Java and
        Java EE
       Authored a book on Struts
       Several articles on Java EE for leading journals
       Director of Enterprise Java Practice at
        ObjectSource
       Creator of FxObjects and FxContainer framework
Introduction
   What is FxContainer? (Currently 1.0)
       Open source IoC container written in JavaFX.
       Meant specifically for Dependency Injection in
        JavaFX applications
       Very much Spring-like
       Small footprint (< 75K)
       Sequence, Collection Support
       Mix Java and JavaFX wiring
   Learn FxContainer in 20 slides! (10 minutes)
IoC Container Landscape
   Spring
       Supports XML and Annotations based DI
       Supports Constructor & Setter Injection
   Guice
       Supports Annotations and API based DI
       Supports Constructor & Setter Injection
   PicoContainer and many more..
Why another IoC Container?
   Problems with existing IoC Containers (in the
    context of JavaFX)
       JavaFX does not support annotations 
           Hence Guice leaves only programmatic DI option
           Xml DI with Spring works, but minimal jars > 1 MB
       Constructor Injection not supported in JavaFX
       Setter Injection is unnatural for JavaFX style
           JavaFX variables are written as public or public-init
           Writing setXYZ() method for variables feels artificial
       Nobody supports Sequence (the first class
        JavaFX collection citizen)
Setter Injection
var finder = MovieFinder {
  movieDao: MovieDao { }
}

   Dependency Injection with any other IoC
    container needs a setter like this (Not Good)
public class MovieFinder {
  public-init movieDao:MovieDao;
  public function setMovieDao(dao:MovieDao) {
    this.movieDao = dao;
  }
}
Side effects of Setter Injection
   Init and Post-Init code that depends on
    public-init variables will not work
   Classic Example – CustomNode.create()
       Called automatically in every UI
       Called immediately after init and post init
       No time to call setter methods
       If create() depends on objects injected by setter
        injection, then it will fail !!
A Different Kind of Injection
 Constructor Injection is DURING memory
  allocation
 Setter Injection is AFTER memory allocation
  and object initialization
 JavaFX needs something in between the two

 We call it Init injection

 A DI based on Init Injection does not exist

 So we created it 
 FxContainer is the ONLY IoC container that
        provides Init Injection for JavaFX
FxContainer Core Concept
   Based on JavaFX Reflection and Init Injection
FXLocal.Context ctx = FXLocal.getContext();

//get the class
FXClassType clzType = ctx.findClass("org.fxobjects.MovieFinder");

FXObjectValue objValue = clzType.allocate(); //allocate memory

//get the variable-type
FXVarMember varMember = clzType.getVariable("movieDao");

//create the variable-value
FXValue varValue = ctx.mirrorOf(Some String or object);

//initialize the variable. Basis for FxContainer Init Injection

objValue.initVar(varMember, varValue);
objValue.initialize(); //Finally initialize the object
FxContainer Overview
   Uses Setter Injection for Java objects
   Uses Init Injection for JavaFX objects
   Can mix both Java and JavaFX objects
   Java objects can hold references to JavaFX
    objects via interfaces
   Very Spring Like in configuration
   Powerful, Lightweight and Easy to use
FxContainer: Simple
Dependency Injection
<fxcontainer>

<fxobject name="movieFinder"
  class="org.fxobjects.samples.fxcontainer.MovieFinderImpl">
  <property name="someVar" value="Some random value"/>
  <property name="javaHelper" ref="javaHelperObj"/>
  <property name="jfxHelper" ref="jfxHelperVarObj"/>
</fxobject>

<fxobject name="movieLister"
  class="org.fxobjects.samples.fxcontainer.MovieLister">
  <property name="finder" ref="movieFinder"/>
</fxobject>

</fxcontainer>
FxContainer: Import XML
   Good for organizing large XML into smaller
    logical chunks
<fxcontainer>

<import resource="/org/fxobjects/samples/abc.xml"/>

<fxobject name="movieFinder"
  class="org.fxobjects.samples.fxcontainer.MovieFinderImpl">
  <property name="someVar" value="Some random value"/>
  <property name="javaHelper" ref="javaHelperObj"/>
  <property name="jfxHelper" ref="jfxHelperVarObj"/>
</fxobject>

</fxcontainer>
FxContainer: Import Properties
   Good for Spring style ${ } substitutions
<fxcontainer>

<import resource="/org/fxobjects/samples/abc.properties"/>

<fxobject name="movieFinder"
  class="org.fxobjects.samples.fxcontainer.MovieFinderImpl">
  <property name="someVar" value=“${svr1Name} is ${svr1Status}"/>
  <property name="javaHelper" ref=“${helperObj}"/>
  <property name="jfxHelper" ref="jfxHelperVarObj"/>
</fxobject>

</fxcontainer>

   value and ref can be substituted
FxContainer: Wired Object
Attributes
   Wired Objects in FxContainer have the following defaults
    (can be overridden)
       Every wired object is singleton
       Every wired object is lazily initialized (i.e on demand)
       There is no order of initialization (Although load order can be
        specified for eagerly loaded objects)
       Init-method is called after all properties are injected
<fxcontainer>
<fxobject name="movieFinder"
   class="org.fxobjects.samples.fxcontainer.MovieFinderImpl“ lazy-
   init=“false” load-order=“1” init-method=“someMethod”>
..
 </fxobject>
</fxcontainer>
FxContainer: Sequences
<fxcontainer>
 <fxobject name="movieFinder"
   class="org.fxobjects.samples.fxcontainer.MovieFinderImpl">
   <property name="movieCodes">     Primitive Sequence
     <sequence>
       <entry value=“1" />
       <entry value="2" />
     </sequence>
   </property>
   <property name="movies">         Object Sequence
     <sequence>
       <entry ref="movie1"/>
       <entry ref="movie2"/>
     </sequence>
   </property>
  </fxobject>
</fxcontainer>
FxContainer: Lists and Sets
<fxcontainer>
 <fxobject name="movieFinder"
   class="org.fxobjects.samples.fxcontainer.MovieFinderImpl">
   <property name="movieList">              Object LIST
     <list> (or <set>)
       <entry ref="movie1"/>
       <entry ref="movie2"/>
     </list>
   </property>
   <property name="movieCodes">             Primitive LIST
     <list valueClass=“java.lang.Integer”>
       <entry value=“1" />
       <entry value="2" />
     </list>
   </property>
  </fxobject>
</fxcontainer>
FxObjects Lists and Sets
(Contd.)
   Lists and Sets have to be initialized in their
    parents with a new …..();
   valueClass attribute
       Optional in most cases
       Reason: One cannot tell from the xml value
        attributed if a list is Integer, String, BigDecimal
        etc.
       Needed for Java and JavaFX objects when
           value attribute is specified in xml AND
           List is not parameterized (always the case in JavaFX)
FxContainer: Maps
<fxcontainer>
 <fxobject name="movieFinder"
   class="org.fxobjects.samples.fxcontainer.MovieFinderImpl">
   <property name="movieMap">              Object MAP
     <map>
       <entry keyRef=“stage1” valueRef="movie1"/>
     </map>
   </property>
   <property name="movieCodes">             Primitive MAP
    <map keyClass=“java.lang.String”
   valueClass=“java.lang.Integer”>
       <entry key=“Terminator 1” value=“1" />
       <entry value=“Terminator 2" />
     </map>
   </property>
  </fxobject>
</fxcontainer>
keyClass and valueClass are needed for Maps in JavaFX with key
   and value specified. (since they cannot be parameterized) and
FxContainer: Startup
   Spring Like
var loader = ClasspathXmlContainerLoader {
  resourceLocation: "/org/fxobjects/samples/my.xml“
}
var container:FxContainer = loader.load();
var mvLister:MovieLister =
      container.getFxObject("movieLister") as MovieLister;

   FxContainer can be used the IoC container
    with FxObjects or any other JavaFX
    application independently
   Just include 2 jars – fxcontainer.jar and
    fxobjects-util.jar in classpath
FxObjects & FxContainer:
Roadmap
Links
   Project site – https://fxobjects/dev.java.net
   FxContainer is a subproject of FxObjects
   Not a single person open source project
       FxObjects and FxContainer developed and supported
        by ObjectSource (http://www.objectsource.com)
   Download, use, extend, redistribute, OEM
   Discussion Forums on project site
   Participation welcome
       Post ideas, questions, concerns, comments
       Contribute code

Weitere ähnliche Inhalte

Was ist angesagt?

Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaSanjeev Tripathi
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
 
RelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaRelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaJose María Arranz
 
Javascript closures
Javascript closures Javascript closures
Javascript closures VNG
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpdayStephan Hochdörfer
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applicationsDmitry Matyukhin
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java CertificationVskills
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughMahfuz Islam Bhuiyan
 

Was ist angesagt? (20)

Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
Java basic
Java basicJava basic
Java basic
 
Java 9
Java 9Java 9
Java 9
 
Invoke dynamics
Invoke dynamicsInvoke dynamics
Invoke dynamics
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Java byte code in practice
Java byte code in practiceJava byte code in practice
Java byte code in practice
 
RelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaRelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with Java
 
Javascript closures
Javascript closures Javascript closures
Javascript closures
 
Fixing the Java Serialization Mess
Fixing the Java Serialization Mess Fixing the Java Serialization Mess
Fixing the Java Serialization Mess
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Javatut1
Javatut1 Javatut1
Javatut1
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpday
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applications
 
Basic java for Android Developer
Basic java for Android DeveloperBasic java for Android Developer
Basic java for Android Developer
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java Certification
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
 

Ähnlich wie JavaFX Dependency Injection with FxContainer

Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsSrikanth Shenoy
 
JavaFX for Business Application Developers
JavaFX for Business Application DevelopersJavaFX for Business Application Developers
JavaFX for Business Application DevelopersMichael Heinrichs
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
EclipseCon 2010 - JDT Fundamentals
EclipseCon 2010 - JDT FundamentalsEclipseCon 2010 - JDT Fundamentals
EclipseCon 2010 - JDT Fundamentalsdeepakazad
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignJames Phillips
 
DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)Hendrik Ebbers
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2Leonid Maslov
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryWingify Engineering
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneDeepu S Nath
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConos890
 
Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Paddy Lock
 

Ähnlich wie JavaFX Dependency Injection with FxContainer (20)

Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjects
 
DataFX - JavaOne 2013
DataFX - JavaOne 2013DataFX - JavaOne 2013
DataFX - JavaOne 2013
 
JavaFX for Business Application Developers
JavaFX for Business Application DevelopersJavaFX for Business Application Developers
JavaFX for Business Application Developers
 
Javaee6 Overview
Javaee6 OverviewJavaee6 Overview
Javaee6 Overview
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
EclipseCon 2010 - JDT Fundamentals
EclipseCon 2010 - JDT FundamentalsEclipseCon 2010 - JDT Fundamentals
EclipseCon 2010 - JDT Fundamentals
 
JDT Fundamentals 2010
JDT Fundamentals 2010JDT Fundamentals 2010
JDT Fundamentals 2010
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class Design
 
DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)
 
Spring
SpringSpring
Spring
 
Signal Framework
Signal FrameworkSignal Framework
Signal Framework
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
What's new in Java EE 6
What's new in Java EE 6What's new in Java EE 6
What's new in Java EE 6
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG June
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
 
Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners
 

Kürzlich hochgeladen

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

JavaFX Dependency Injection with FxContainer

  • 1. JavaFX Dependency Injection with FxContainer Presented by Srikanth Shenoy ObjectSource Learn FxContainer in 10 minutes
  • 2. Introduction  Who am I?  A hands-on architect  Experienced and very knowledgeable in Java and Java EE  Authored a book on Struts  Several articles on Java EE for leading journals  Director of Enterprise Java Practice at ObjectSource  Creator of FxObjects and FxContainer framework
  • 3. Introduction  What is FxContainer? (Currently 1.0)  Open source IoC container written in JavaFX.  Meant specifically for Dependency Injection in JavaFX applications  Very much Spring-like  Small footprint (< 75K)  Sequence, Collection Support  Mix Java and JavaFX wiring  Learn FxContainer in 20 slides! (10 minutes)
  • 4. IoC Container Landscape  Spring  Supports XML and Annotations based DI  Supports Constructor & Setter Injection  Guice  Supports Annotations and API based DI  Supports Constructor & Setter Injection  PicoContainer and many more..
  • 5. Why another IoC Container?  Problems with existing IoC Containers (in the context of JavaFX)  JavaFX does not support annotations   Hence Guice leaves only programmatic DI option  Xml DI with Spring works, but minimal jars > 1 MB  Constructor Injection not supported in JavaFX  Setter Injection is unnatural for JavaFX style  JavaFX variables are written as public or public-init  Writing setXYZ() method for variables feels artificial  Nobody supports Sequence (the first class JavaFX collection citizen)
  • 6. Setter Injection var finder = MovieFinder { movieDao: MovieDao { } }  Dependency Injection with any other IoC container needs a setter like this (Not Good) public class MovieFinder { public-init movieDao:MovieDao; public function setMovieDao(dao:MovieDao) { this.movieDao = dao; } }
  • 7. Side effects of Setter Injection  Init and Post-Init code that depends on public-init variables will not work  Classic Example – CustomNode.create()  Called automatically in every UI  Called immediately after init and post init  No time to call setter methods  If create() depends on objects injected by setter injection, then it will fail !!
  • 8. A Different Kind of Injection  Constructor Injection is DURING memory allocation  Setter Injection is AFTER memory allocation and object initialization  JavaFX needs something in between the two  We call it Init injection  A DI based on Init Injection does not exist  So we created it  FxContainer is the ONLY IoC container that provides Init Injection for JavaFX
  • 9. FxContainer Core Concept  Based on JavaFX Reflection and Init Injection FXLocal.Context ctx = FXLocal.getContext(); //get the class FXClassType clzType = ctx.findClass("org.fxobjects.MovieFinder"); FXObjectValue objValue = clzType.allocate(); //allocate memory //get the variable-type FXVarMember varMember = clzType.getVariable("movieDao"); //create the variable-value FXValue varValue = ctx.mirrorOf(Some String or object); //initialize the variable. Basis for FxContainer Init Injection objValue.initVar(varMember, varValue); objValue.initialize(); //Finally initialize the object
  • 10. FxContainer Overview  Uses Setter Injection for Java objects  Uses Init Injection for JavaFX objects  Can mix both Java and JavaFX objects  Java objects can hold references to JavaFX objects via interfaces  Very Spring Like in configuration  Powerful, Lightweight and Easy to use
  • 11. FxContainer: Simple Dependency Injection <fxcontainer> <fxobject name="movieFinder" class="org.fxobjects.samples.fxcontainer.MovieFinderImpl"> <property name="someVar" value="Some random value"/> <property name="javaHelper" ref="javaHelperObj"/> <property name="jfxHelper" ref="jfxHelperVarObj"/> </fxobject> <fxobject name="movieLister" class="org.fxobjects.samples.fxcontainer.MovieLister"> <property name="finder" ref="movieFinder"/> </fxobject> </fxcontainer>
  • 12. FxContainer: Import XML  Good for organizing large XML into smaller logical chunks <fxcontainer> <import resource="/org/fxobjects/samples/abc.xml"/> <fxobject name="movieFinder" class="org.fxobjects.samples.fxcontainer.MovieFinderImpl"> <property name="someVar" value="Some random value"/> <property name="javaHelper" ref="javaHelperObj"/> <property name="jfxHelper" ref="jfxHelperVarObj"/> </fxobject> </fxcontainer>
  • 13. FxContainer: Import Properties  Good for Spring style ${ } substitutions <fxcontainer> <import resource="/org/fxobjects/samples/abc.properties"/> <fxobject name="movieFinder" class="org.fxobjects.samples.fxcontainer.MovieFinderImpl"> <property name="someVar" value=“${svr1Name} is ${svr1Status}"/> <property name="javaHelper" ref=“${helperObj}"/> <property name="jfxHelper" ref="jfxHelperVarObj"/> </fxobject> </fxcontainer>  value and ref can be substituted
  • 14. FxContainer: Wired Object Attributes  Wired Objects in FxContainer have the following defaults (can be overridden)  Every wired object is singleton  Every wired object is lazily initialized (i.e on demand)  There is no order of initialization (Although load order can be specified for eagerly loaded objects)  Init-method is called after all properties are injected <fxcontainer> <fxobject name="movieFinder" class="org.fxobjects.samples.fxcontainer.MovieFinderImpl“ lazy- init=“false” load-order=“1” init-method=“someMethod”> .. </fxobject> </fxcontainer>
  • 15. FxContainer: Sequences <fxcontainer> <fxobject name="movieFinder" class="org.fxobjects.samples.fxcontainer.MovieFinderImpl"> <property name="movieCodes">  Primitive Sequence <sequence> <entry value=“1" /> <entry value="2" /> </sequence> </property> <property name="movies">  Object Sequence <sequence> <entry ref="movie1"/> <entry ref="movie2"/> </sequence> </property> </fxobject> </fxcontainer>
  • 16. FxContainer: Lists and Sets <fxcontainer> <fxobject name="movieFinder" class="org.fxobjects.samples.fxcontainer.MovieFinderImpl"> <property name="movieList">  Object LIST <list> (or <set>) <entry ref="movie1"/> <entry ref="movie2"/> </list> </property> <property name="movieCodes">  Primitive LIST <list valueClass=“java.lang.Integer”> <entry value=“1" /> <entry value="2" /> </list> </property> </fxobject> </fxcontainer>
  • 17. FxObjects Lists and Sets (Contd.)  Lists and Sets have to be initialized in their parents with a new …..();  valueClass attribute  Optional in most cases  Reason: One cannot tell from the xml value attributed if a list is Integer, String, BigDecimal etc.  Needed for Java and JavaFX objects when  value attribute is specified in xml AND  List is not parameterized (always the case in JavaFX)
  • 18. FxContainer: Maps <fxcontainer> <fxobject name="movieFinder" class="org.fxobjects.samples.fxcontainer.MovieFinderImpl"> <property name="movieMap">  Object MAP <map> <entry keyRef=“stage1” valueRef="movie1"/> </map> </property> <property name="movieCodes">  Primitive MAP <map keyClass=“java.lang.String” valueClass=“java.lang.Integer”> <entry key=“Terminator 1” value=“1" /> <entry value=“Terminator 2" /> </map> </property> </fxobject> </fxcontainer> keyClass and valueClass are needed for Maps in JavaFX with key and value specified. (since they cannot be parameterized) and
  • 19. FxContainer: Startup  Spring Like var loader = ClasspathXmlContainerLoader { resourceLocation: "/org/fxobjects/samples/my.xml“ } var container:FxContainer = loader.load(); var mvLister:MovieLister = container.getFxObject("movieLister") as MovieLister;  FxContainer can be used the IoC container with FxObjects or any other JavaFX application independently  Just include 2 jars – fxcontainer.jar and fxobjects-util.jar in classpath
  • 21. Links  Project site – https://fxobjects/dev.java.net  FxContainer is a subproject of FxObjects  Not a single person open source project  FxObjects and FxContainer developed and supported by ObjectSource (http://www.objectsource.com)  Download, use, extend, redistribute, OEM  Discussion Forums on project site  Participation welcome  Post ideas, questions, concerns, comments  Contribute code