Skip to Content
Practical JSF in Java EE 8: Web Applications ​in Java for the Enterprise
book

Practical JSF in Java EE 8: Web Applications ​in Java for the Enterprise

by Michael Müller
May 2018
Intermediate to advanced
471 pages
10h 25m
English
Apress
Content preview from Practical JSF in Java EE 8: Web Applications ​in Java for the Enterprise
© Michael Müller 2018
Michael MüllerPractical JSF in Java EE 8 https://doi.org/10.1007/978-1-4842-3030-5_16

16. Contexts and Dependency Injection

Michael Müller1 
(1)
Brühl, Nordrhein-Westfalen, Germany
 

Sometimes you need an instance of an object with a type that might be changed or determined at runtime, and you need a reliable mechanism to perform that task. Luckily, Java EE 8 comes with Contexts and Dependency Injection (CDI), which can solve the problem.

From new() to CDI

If you write a class that needs access to an underlying object-oriented service, you need to obtain an instance of this service and call its methods. One simple approach is to create a new object of the service class:

DataService dataService = new DataService();

That approach has ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java for the Web with Servlets, JSP, and EJB: A Developer’s Guide to J2EE Solutions

Java for the Web with Servlets, JSP, and EJB: A Developer’s Guide to J2EE Solutions

Budi Kurniawan
Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Jonathan Wetherbee, Massimo Nardone, Chirag Rathod, Raghu Kodali
Java EE 7 Development with WildFly

Java EE 7 Development with WildFly

Michal Cmil, Michal Matloka, Francesco Marchioni

Publisher Resources

ISBN: 9781484230305Purchase LinkPublisher Website