Dependency injection 1.0 for Java

This specification is provided by the javax.inject API. This is a set of packages specifying a means of getting objects in such a way as to achieve major reusability, testability, and maintainability compared to traditional approaches such as constructors, factories, and service locators. This process, known as dependency injection, is beneficial to most non-trivial applications.

With CDI, you don't instantiate the classes. CDI takes care of it. An internal management of the instances lets the developer create better features for the application. Instances are a point of work where we resolve performance problems. All this becomes simpler using a CDI engine.

Take, for example, a book service:

class BookService {
final List<Book> books;
BookService () {
books = new ArrayList(...);
}
}

Using the new construct, we are adding health to our application. A good developer knows the correct time to instantiate own objects. By using this annotation, he/she doesn't need to worry about it:

 class BookService {
@Inject
final List<Book> books;
}

Weld will work to instantiate the list of books and cache the result according to its scope.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.131.178