Java 9 Dependency Injection
Nilang Patel, Krunal Patel
- 246 pagine
- English
- ePUB (disponibile sull'app)
- Disponibile su iOS e Android
Java 9 Dependency Injection
Nilang Patel, Krunal Patel
Informazioni sul libro
Create clean code with Dependency Injection principles
Key Features
- Use DI to make your code loosely coupled to manage and test your applications easily on Spring 5 and Google Guice
- Learn the best practices and methodologies to implement DI
- Write more maintainable Java code by decoupling your objects from their implementations
Book Description
Dependency Injection (DI) is a design pattern that allows us to remove the hard-coded dependencies and make our application loosely coupled, extendable, and maintainable. We can implement DI to move the dependency resolution from compile-time to runtime. This book will be your one stop guide to write loosely coupled code using the latest features of Java 9 with frameworks such as Spring 5 and Google Guice.
We begin by explaining what DI is and teaching you about IoC containers. Then you'll learn about object compositions and their role in DI. You'll find out how to build a modular application and learn how to use DI to focus your efforts on the business logic unique to your application and let the framework handle the infrastructure work to put it all together.
Moving on, you'll gain knowledge of Java 9's new features and modular framework and how DI works in Java 9. Next, we'll explore Spring and Guice, the popular frameworks for DI. You'll see how to define injection keys and configure them at the framework-specific level. After that, you'll find out about the different types of scopes available in both popular frameworks. You'll see how to manage dependency of cross-cutting concerns while writing applications through aspect-oriented programming.
Towards the end, you'll learn to integrate any third-party library in your DI-enabled application and explore common pitfalls and recommendations to build a solid application with the help of best practices, patterns, and anti-patterns in DI.
What you will learn
- Understand the benefits of DI and fo from a tightly coupled design to a cleaner design organized around dependencies
- See Java 9's new features and modular framework
- Set up Guice and Spring in an application so that it can be used for DI
- Write integration tests for DI applications
- Use scopes to handle complex application scenarios
- Integrate any third-party library in your DI-enabled application
- Implement Aspect-Oriented Programming to handle common cross-cutting concerns such as logging, authentication, and transactions
- Understand IoC patterns and anti-patterns in DI
Who this book is for
This book is for Java developers who would like to implement DI in their application. Prior knowledge of the Spring and Guice frameworks and Java programming is assumed.
Domande frequenti
Informazioni
Dependency Injection with Spring
- A brief introduction to Spring framework
- Bean management in Spring
- How to achieve DI with Spring
- Auto wiring: he feature of resolving dependency automatically
- Annotation-based DI implementation
- DI implementation with Java-based configuration
A brief introduction to Spring framework
Spring framework architecture
- Core container layer
- Data access/integration layer
- Web layer
- Test layer
- Miscellaneous layer
Core container layer
- The setting of and getting properties' values of objects with ease
- It can directly invoke controller methods to get the data
- It's used to retrieve objects directly from Spring's application context (IoC container)
- It supports various list operations such as projection, selection, iteration, and aggregation
- It provides logical and arithmetic operations
Data access/integration layer
- Transaction: This module helps maintain transactions in a programmatic and declarative manner. This module supports ORM and JDBC modules.
- Object XML mapping (OXM): This module provides abstraction of Object/XML processing, which can be used by various OXM implementation such as JAXB, XMLBeans, and so on, to integrate with Spring.
- Object Relationship Mapping (ORM): Spring doesn't provide its own ORM framework; instead it facilitates integration with ORM frameworks such as Hibernate, JPA, JDO, and so on, with this module.
- Java Database Connectivity (JDBC): This module provides all low-level boilerplate code to deal with JDBC. You can use it to interact with databases with standard JDBC API.
- Java Messaging Service (JMS): This module supports integration of messaging systems in Spring.
Spring web layer
- Web: This module provides basic web-related features such as multipart file upload (with the help of Spring custom tags in JSP). It is also responsible for initialization of IoC containers in web context.
- Servlet: This module provides implementation of Spring MVC (Model View Controller) for web-based applications. It provides clear separation of views (presentation layer) from models (business logic), and controls the flow between them with controllers.
- Portlet: This module provides MVC implementation for a portlet, and it is mainly used in portal environments.
Spring test
Miscellaneous
- Aspect and AOP: These modules provide a facility to apply common logic (called concerns in AOP terminology) across multiple application layers dynamically
- Instrumentation: This module provides a class instrumentation facility and class loader implementation
- Messaging: This module provides support for Streaming Text-Oriented Messaging Protocol (STOMP) for communicating with various STOMP-based clients
Bean management in Spring container
Spring IoC container
- FileSystemXmlApplicationContext: This conta...