万本电子书0元读

万本电子书0元读

顶部广告

Java 9 Dependency Injection电子书

售       价:¥

9人正在读 | 0人评论 6.2

作       者:Krunal Patel,Nilang Patel

出  版  社:Packt Publishing

出版时间:2018-04-26

字       数:31.0万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Create clean code with Dependency Injection principles About This Book ? 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 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. 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 In Detail 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. Style and approach This book will take an easy-to-understand, step-by-step approach providing hands-on examples at every stage.
目录展开

Title Page

Copyright and Credits

Java 9 Dependency Injection

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the authors

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Why Dependency Injection?

Design patterns

Dependency Inversion Principle

Inversion of Control

Implementing DIP through IoC

Inverting the interface

Inverting object creation

Different ways to invert object creation

Inversion of object creation through the factory pattern

Inversion of object creation through service locator

Dependency injection

Dependency injection types

Constructor injection

Setter injection

Interface injection

IoC containers

Summary

Dependency Injection in Java 9

Java 9 introduction

Key features

Java Platform Module System

JShell (REPL) – The Java Shell

JLink – Module Linker

Multi-release JAR files

Stream API enhancements

Stack-walking API

Immutable collections with convenient factory methods

HTTP/2.0 support

Modular Framework in Java 9

What is modularity?

Java Platform Module System

The need for a Java modular system

Modular JDK

What is a module?

Structure of a module

Module Descriptor (module-info.java)

Module types

Dependency Injection using the Java 9 Modular Framework

Modules with Service Loader

Service (API) module

Service provider (Implementation) module

Service client application

Writing modular code using a command-line interface

Defining dependency between modules

Compiling and running modules

Summary

Dependency Injection with Spring

A brief introduction to Spring framework

Spring framework architecture

Core container layer

Data access/integration layer

Spring web layer

Spring test

Miscellaneous

Bean management in Spring container

Spring IoC container

Configuration

Containers in action

Dependency Injection (DI) in Spring

Constructor-based DI

Setter-based DI

Spring DI with the factory method

Static factory method

Instance (non-static) factory method

Auto-wiring in Spring

Auto-wiring by name

Auto-wiring by type

Auto-wiring by constructor

Annotation-based DI

DI through XML configuration

Defining annotation

Activating annotation-based configuration

Defining a Java class as <bean> with annotation

Annotation with the factory method

DI with Java configuration

Summary

Dependency Injection with Google Guice

A brief introduction to the Google Guice framework

Guice setup

Dependency injection and JSR-330

Example of simple DI

Basic injection in Guice

Guice API and Phases

Start up phase

Module interface

The AbstractModule class

Binder

Injector

Guice

Provider

Runtime phase

Guice annotations

Inject

ProvidedBy

ImplementedBy

@Named

Binding in Guice

Linked bindings

Instance bindings

Untargeted bindings

Constructor bindings

Built-in bindings

Just-in-time Bindings

Binding annotations

Guice injection

Constructor Injection

Method injection

Field injection

Optional injection

Static injection

Summary

Scopes

Introduction to bean scopes in Spring

Bean definition

Spring scopes

Singleton scope

Prototype scope

Request scope

Session scope

Application scope

Global session scope

websocket scope

How to define a bean scope

XML metadata configuration

Using the singleton scope

Using the prototype scope

Java configuration using annotations

Singleton scope with annotation

Prototype scope with annotation

Dependency injection and the bean scope

How to choose a bean scope

Scopes in Google Guice

Default scope

Singleton scope

Eager singletons

Summary

Aspect-Oriented Programming and Interceptors

AOP introduction

Spring AOP

XML(schema)-based Spring AOP

Declaring aspect

Declaring a point-cut

Point-cut designator

Patterns

Declaring Advice (interceptor)

Implementing before advice

Implementing after advice

Implementing around advice

Implementing after returning advice

Implementing AfterThrowing advice

@AspectJ annotation-based Spring AOP

Declaring aspect

Declaring point-cut

Declaring Advice

Declaring an advisor

Choosing AOP frameworks and style of configuration

Spring AOP versus AspectJ language

XML versus @AspectJ-style annotation for Spring AOP

Summary

IoC Patterns and Best Practices

Various patterns to achieve IoC

The factory method pattern

Defining the product (abstract type) and its concrete implementation

Defining the factory method (creator interface) and its concrete implementation

The service locator pattern

The template method pattern

The strategy pattern

Configuration styles

File-based (XML) versus code-based configuration

Injection using the setter method versus the constructor

Constructor-based DI

Setter-based DI

Circular dependency

Problems of circular dependency

Causes and solutions

The single responsibility principle

Deferring the setting of a dependency from constructor to setter

Relocation of classes and packages

Circular dependency in the Spring framework

Using setter/field injection over constructor injection

Using the @Lazy annotation

Best practices and anti-patterns

What to inject – the container itself or just dependencies?

Excessive injection

Achieving IoC in the absence of a container

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部