├── .gitignore ├── README.md ├── cdi-alternatives ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── craftcoder │ │ └── cdi │ │ └── alternatives │ │ ├── LocaleDiscovery.java │ │ ├── MainApplication.java │ │ ├── Moip.java │ │ ├── MoipPayment.java │ │ ├── PayPal.java │ │ ├── PayPalPayment.java │ │ ├── Payment.java │ │ ├── PaymentService.java │ │ └── PaymentServiceWithAlternatives.java │ └── resources │ └── META-INF │ └── beans.xml ├── cdi-injection-point ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── craftcoder │ │ └── cdi │ │ └── injectionpoint │ │ ├── Checkout.java │ │ ├── Logger.java │ │ ├── LoggerFactory.java │ │ ├── MainApplication.java │ │ └── Payment.java │ └── resources │ └── META-INF │ └── beans.xml ├── cdi-interceptors ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── hackingcode │ │ └── cdi │ │ └── produces │ │ ├── Auditable.java │ │ ├── Auditor.java │ │ ├── AuditorInterceptor.java │ │ ├── Checkout.java │ │ ├── Loggable.java │ │ ├── LoggerInterceptor.java │ │ ├── MainApplication.java │ │ └── MyLogger.java │ └── resources │ └── META-INF │ └── beans.xml ├── cdi-lazy-injection ├── 1 ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── craftcoder │ │ └── cdi │ │ └── produces │ │ ├── Buyer.java │ │ ├── Checkout.java │ │ ├── CheckoutEvent.java │ │ ├── EmailSender.java │ │ ├── MainApplication.java │ │ ├── MetricCreator.java │ │ ├── Order.java │ │ └── User.java │ └── resources │ └── META-INF │ └── beans.xml ├── cdi-observers-events ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── craftcoder │ │ └── cdi │ │ └── produces │ │ ├── Buyer.java │ │ ├── Checkout.java │ │ ├── CheckoutEvent.java │ │ ├── EmailSender.java │ │ ├── MainApplication.java │ │ ├── MetricCreator.java │ │ └── Order.java │ └── resources │ └── META-INF │ └── beans.xml ├── cdi-produces ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── hackingcode │ │ └── cdi │ │ └── produces │ │ ├── AwesomeLoggerFactory.java │ │ ├── Checkout.java │ │ ├── LogConfiguration.java │ │ ├── MainApplication.java │ │ └── SpecialLogger.java │ └── resources │ └── META-INF │ └── beans.xml ├── cdi-qualifiers ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── craftcoder │ │ └── cdi │ │ └── qualifiers │ │ ├── AwesomeLogger.java │ │ ├── AwesomeLoggerFactory.java │ │ ├── Checkout.java │ │ ├── DebugMode.java │ │ ├── InfoMode.java │ │ ├── LogConfiguration.java │ │ ├── LoggerMode.java │ │ ├── MainApplication.java │ │ └── WarnMode.java │ └── resources │ └── META-INF │ └── beans.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CDI Guides and Tutorials - Hacking Code 2 | 3 | This GitHub Repository belogs to [Hacking Code Site](https://blog.hackingcode.io/?utm_source=github&utm_medium=cdi-guide-tutorials) founded by [@alexandregama](https://github.com/alexandregama), that has many **Articles**, **Guides** and **Tutorials** about many frameworks and libraries like: 4 | 5 | - [CDI](https://blog.hackingcode.io/cdi-guides-posts-news-and-tutorials/?utm_source=github&utm_medium=cdi-guide-tutorials) 6 | - [Java 8](https://blog.hackingcode.io/java-8-tutorials-guides-ebooks-courses/?utm_source=github&utm_medium=java8-guide-tutorials) 7 | - [JUnit](https://blog.hackingcode.io/junit-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials) 8 | - [Mockito](https://blog.hackingcode.io/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials) 9 | 10 | If you are interested in **CDI Articles**, you can learn a lot of **CDI Features** in the following links :) 11 | 12 | - [CDI Qualifiers Tutorial](https://blog.hackingcode.io/cdi-qualifiers-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-guide-tutorials) 13 | - [CDI Observers and Events Tutorial](https://blog.hackingcode.io/cdi-events-and-observers-java-tutorial/?utm_source=github&utm_medium=cdi-guide-tutorials) 14 | - [CDI Lazy Initialization Tutorial](https://blog.hackingcode.io/cdi-lazy-initialization-java-tutorial/?utm_source=github&utm_medium=cdi-guide-tutorials) 15 | - [CDI How to use Interceptors](https://blog.hackingcode.io/cdi-interceptors-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-guide-tutorials) 16 | - [CDI Alternatives Tutorial](https://blog.hackingcode.io/cdi-alternatives-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-guide-tutorials) 17 | - [CDI How to use Decorators](https://blog.hackingcode.io/cdi-decorators-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-guide-tutorials) 18 | 19 | # Java 8 Guides and Tutorials 20 | 21 | **Java 8** changed the way that we think and code. Here you will see a **lot of articles and tutorials** 22 | about Java 8, how to use its awesome features and how to get your life easier! Enjoy! 23 | 24 | - [JUnit Main Page](https://blog.hackingcode.io/java-8-tutorials-guides-ebooks-courses/?utm_source=github&utm_medium=cdi-guide-tutorials) 25 | - [GitHub Main Page](https://github.com/hacking-code/java8-guides-tutorials) 26 | 27 | ### Articles and Tutorials about Java 8 28 | 29 | - [Java 8 - Lambda Expression](https://blog.hackingcode.io/java-8-lambda-expression-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 30 | - [Java 8 - Default Methods](https://blog.hackingcode.io/java-8-default-methods-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 31 | - [Java 8 - Functions](https://blog.hackingcode.io/java-8-functions-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 32 | - [Java 8 - Method Reference](https://blog.hackingcode.io/java-8-method-reference-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 33 | - [Java 8 - Stream Count](https://blog.hackingcode.io/java-8-stream-count-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 34 | - [Java 8 - Stream with Filter](https://blog.hackingcode.io/java-8-stream-filter-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 35 | - [Java 8 - Stream with Map](https://blog.hackingcode.io/java-8-stream-map-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 36 | - [Java 8 - Stream with Sorted](https://blog.hackingcode.io/java-8-stream-sorted-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 37 | - [Java 8 - Stream with Match](https://blog.hackingcode.io/java-8-stream-match-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 38 | - [Java 8 - Stream Reduce](https://blog.hackingcode.io/java-8-stream-reduce-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 39 | - [Java 8 - Stream Consumer](https://blog.hackingcode.io/java-8-consumers-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 40 | - [Java 8 - Predicate](https://blog.hackingcode.io/java-8-predicate-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 41 | - [Java 8 - Comparator](https://blog.hackingcode.io/java-8-comparator-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 42 | - [Java 8 - Suppliers](https://blog.hackingcode.io/java-8-suppliers-tutorial-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 43 | 44 | # JUnit Guides and Tutorials 45 | 46 | Are you interested in learn about **JUnit Framework**? Maybe you would like to see a lot of great JUnit Features in [Hacking Code Site](https://blog.hackingcode.io/?utm_source=github&utm_medium=cdi-guide-tutorials) in the following links: 47 | 48 | - [JUnit Main Page](https://blog.hackingcode.io/junit-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials) 49 | - [GitHub Main Page](https://github.com/hacking-code/junit-guides-tutorials) 50 | 51 | ### Articles and Tutorials about JUnit 52 | 53 | - [JUnit - How to Configure JUnit 4 and JUnit 5](https://blog.hackingcode.io/junit-tutorial-how-to-configuration-junit4-and-junit5/?utm_source=github&utm_medium=cdi-guide-tutorials) 54 | - [JUnit - Mastering JUnit Assertions](https://blog.hackingcode.io/junit-tutorial-mastering-junit-assertions-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 55 | - [JUnit - How to Use Hamcrest Assertions](https://blog.hackingcode.io/junit-tutorial-hamcrest-assertions-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 56 | - [JUnit - How to work with Tests in Suite](https://blog.hackingcode.io/junit-tutorial-tests-in-suite-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 57 | - [JUnit - How to Order your Execution Test](https://blog.hackingcode.io/junit-tutorial-test-execution-order-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 58 | - [JUnit - Testing with Exceptions](https://blog.hackingcode.io/junit-tutorial-testing-exceptions-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 59 | 60 | # Mockito Guides and Tutorials 61 | 62 | **Mockito** is one of the best **Java Libraries** to work with **Unit and Integration Testing**! In the [Hacking Code Site](https://blog.hackingcode.io/?utm_source=github&utm_medium=cdi-guide-tutorials) you can follow a lot of [Mockito Articles and Tutorials](https://blog.hackingcode.io/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials)! Have fun \o/ 63 | 64 | - [Mockito Main Page](https://blog.hackingcode.io/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials) 65 | - [GitHub Main Page](https://github.com/hacking-code/mockito-guide-tutorials) 66 | 67 | ### Articles and Tutorials about Mockito 68 | 69 | - [Mockito - Mocking objects by using mock() and verify()](https://blog.hackingcode.io/mockito-tutorial-mocking-objects-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 70 | - [Mockito - Basic usage of when() and thenReturn() methods](https://blog.hackingcode.io/mockito-tutorial-basic-usage-of-when-and-then-return-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 71 | - [Mockito - Throwing Exceptions by using thenThrow()](https://blog.hackingcode.io/mockito-tutorial-throwing-exceptions-then-throw-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 72 | - [Mockito - Stubying with Fluent Interface](https://blog.hackingcode.io/mockito-tutorial-stubbing-with-fluent-interface-java-guide/) 73 | - [Mockito - Printing Custom Message when the Verify fails](https://blog.hackingcode.io/mockito-tutorial-printing-custom-message-when-the-verify-fails-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 74 | - [Mockito BDD - Behavior Driven Development with Mockito](https://blog.hackingcode.io/mockito-tutorial-bdd-behavior-driven-development-with-mockito-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 75 | - [Mockito - Ignoring Stubs](https://blog.hackingcode.io/mockito-tutorial-ignoring-stubs-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 76 | - [Mockito - Reseting Mock Interactions](https://blog.hackingcode.io/mockito-tutorial-resetting-mock-interactions-java-guide/?utm_source=github&utm_medium=cdi-guide-tutorials) 77 | 78 | # Keep Social :) 79 | 80 | - [Twitter](https://twitter.com/hacking_code) 81 | - [GitHub](https://github.com/hacking-code) 82 | - [Instagram](https://www.instagram.com/hacking_code) 83 | - [Facebook](https://www.facebook.com/hacking.code.academy) 84 | 85 | # About the Author - Alexandre Gama 86 | 87 | Let's keep in touch : ) 88 | 89 | - [Twitter](https://twitter.com/alexandregamma) 90 | - [GitHub](https://github.com/alexandregama) 91 | - [Linkedin](https://www.linkedin.com/in/alexandregama/) 92 | - [Instagram](https://www.instagram.com/alexandregama/) 93 | - [Google+](https://plus.google.com/+AlexandreGamaLima) 94 | - [About.me](https://about.me/alexandregama) 95 | -------------------------------------------------------------------------------- /cdi-alternatives/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /cdi-alternatives/README.md: -------------------------------------------------------------------------------- 1 | [![Stories in Ready](https://badge.waffle.io/craft-coder/cdi-guide-tutorials.png?label=ready&title=Ready)](https://waffle.io/craft-coder/cdi-guide-tutorials) 2 | # CDI Alternatives Tutorial 3 | 4 | Hey! If you are interested in how and why to use CDI Alternatives, just follow the article below from Craft Coder Site 5 | 6 | - [CDI Alternatives - Why and How to Use](http://craft-coder.com/cdi-alternatives-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-alternatives&utm_term=cdi-java) 7 | 8 | # CDI Guides and Tutorials 9 | 10 | This GitHub Repository belogs to [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) founded by [@alexandregama](https://github.com/alexandregama), that has many **Articles**, **Guides** and **Tutorials** about many frameworks and libraries like: 11 | 12 | - [CDI](http://craft-coder.com/cdi-guides-posts-news-and-tutorials/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) 13 | - [JUnit](http://craft-coder.com/junit-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=junit-java) 14 | - [Mockito](http://craft-coder.com/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=mockito-java) 15 | 16 | If you are interested in **CDI Articles**, you can learn a lot of **CDI Features** in the following links :) 17 | 18 | - [CDI Qualifiers Tutorial](http://craft-coder.com/cdi-qualifiers-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 19 | - [CDI Observers and Events Tutorial](http://craft-coder.com/cdi-events-and-observers-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 20 | - [CDI Lazy Initialization Tutorial](http://craft-coder.com/cdi-lazy-initialization-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 21 | - [CDI How to use Interceptors](http://craft-coder.com/cdi-interceptors-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 22 | - [CDI Alternatives Tutorial](http://craft-coder.com/cdi-alternatives-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 23 | - [CDI How to use Decorators](http://craft-coder.com/cdi-decorators-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 24 | 25 | # JUnit Guides and Tutorials 26 | 27 | Are you interested in learn about **JUnit Framework**? Maybe you would like to see a lot of great JUnit Features in [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) in the following links: 28 | 29 | - [JUnit Main Page](http://craft-coder.com/junit-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=junit-tutorial-home&utm_term=junit-java) 30 | - [GitHub Main Page](https://github.com/craft-coder/junit-guides-tutorials) 31 | 32 | ### Articles and Tutorials about JUnit 33 | 34 | - [JUnit - How to Configure JUnit 4 and JUnit 5](http://craft-coder.com/junit-tutorial-how-to-configuration-junit4-and-junit5/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 35 | - [JUnit - Mastering JUnit Assertions](http://craft-coder.com/junit-tutorial-mastering-junit-assertions-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 36 | - [JUnit - How to Use Hamcrest Assertions](http://craft-coder.com/junit-tutorial-hamcrest-assertions-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 37 | - [JUnit - How to work with Tests in Suite](http://craft-coder.com/junit-tutorial-tests-in-suite-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 38 | - [JUnit - How to Order your Execution Test](http://craft-coder.com/junit-tutorial-test-execution-order-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 39 | - [JUnit - Testing with Exceptions](http://craft-coder.com/junit-tutorial-testing-exceptions-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 40 | 41 | # Mockito Guides and Tutorials 42 | 43 | **Mockito** is one of the best **Java Libraries** to work with **Unit and Integration Testing**! In the [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) you can follow a lot of [Mockito Articles and Tutorials](http://craft-coder.com/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=mockito-tutorial-home&utm_term=mockito-java)! Have fun \o/ 44 | 45 | - [Mockito Main Page](http://craft-coder.com/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=mockito-tutorial-home&utm_term=mockito-java) 46 | - [GitHub Main Page](https://github.com/craft-coder/mockito-guide-tutorials) 47 | 48 | ### Articles and Tutorials about Mockito 49 | 50 | - [Mockito - Mocking objects by using mock() and verify()](http://craft-coder.com/mockito-tutorial-mocking-objects-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 51 | - [Mockito - Basic usage of when() and thenReturn() methods](http://craft-coder.com/mockito-tutorial-basic-usage-of-when-and-then-return-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 52 | - [Mockito - Throwing Exceptions by using thenThrow()](http://craft-coder.com/mockito-tutorial-throwing-exceptions-then-throw-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 53 | - [Mockito - Stubying with Fluent Interface](http://craft-coder.com/mockito-tutorial-stubbing-with-fluent-interface-java-guide/) 54 | - [Mockito - Printing Custom Message when the Verify fails](http://craft-coder.com/mockito-tutorial-printing-custom-message-when-the-verify-fails-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 55 | - [Mockito BDD - Behavior Driven Development with Mockito](http://craft-coder.com/mockito-tutorial-bdd-behavior-driven-development-with-mockito-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 56 | - [Mockito - Ignoring Stubs](http://craft-coder.com/mockito-tutorial-ignoring-stubs-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 57 | - [Mockito - Reseting Mock Interactions](http://craft-coder.com/mockito-tutorial-resetting-mock-interactions-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 58 | 59 | # About the Author 60 | 61 | - [Twitter](https://twitter.com/alexandregamma) 62 | - [GitHub](https://github.com/alexandregama) 63 | - [Linkedin](https://www.linkedin.com/in/alexandregama/) 64 | - [Instagram](https://www.instagram.com/alexandregama/) 65 | - [Google+](https://plus.google.com/+AlexandreGamaLima) 66 | - [About.me](https://about.me/alexandregama) 67 | -------------------------------------------------------------------------------- /cdi-alternatives/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-alternatives 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-alternatives 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/LocaleDiscovery.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | import java.util.Locale; 4 | import java.util.Random; 5 | 6 | public class LocaleDiscovery { 7 | 8 | public Locale discovery() { 9 | int number = new Random().nextInt(10); 10 | 11 | if (number % 2 == 0) { 12 | return new Locale("pt", "BR"); 13 | } 14 | return new Locale("en", "US"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | import javax.enterprise.inject.spi.CDI; 4 | 5 | import org.jboss.weld.environment.se.Weld; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) { 10 | try (CDI container = new Weld().initialize()) { 11 | PaymentServiceWithAlternatives paymentService = container.select(PaymentServiceWithAlternatives.class).get(); 12 | 13 | paymentService.startPayment(); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/Moip.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.inject.Qualifier; 9 | 10 | @Qualifier 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.TYPE}) 13 | public @interface Moip { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/MoipPayment.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | //Without any annotation \o/ 4 | public class MoipPayment implements Payment { 5 | 6 | @Override 7 | public void pay() { 8 | System.out.println("Paying with Moip"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/PayPal.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.inject.Qualifier; 9 | 10 | @Qualifier 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.TYPE}) 13 | public @interface PayPal { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/PayPalPayment.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | import javax.enterprise.inject.Alternative; 4 | 5 | @Alternative 6 | public class PayPalPayment implements Payment { 7 | 8 | @Override 9 | public void pay() { 10 | System.out.println("Paying with PayPal"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/Payment.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | public interface Payment { 4 | 5 | public void pay(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | import java.util.Locale; 4 | 5 | import javax.enterprise.inject.Any; 6 | import javax.enterprise.inject.Instance; 7 | import javax.enterprise.util.AnnotationLiteral; 8 | import javax.inject.Inject; 9 | 10 | public class PaymentService { 11 | 12 | private static final Locale BRAZIL = new Locale("pt", "BR"); 13 | 14 | @Inject @Any 15 | private Instance payments; 16 | 17 | @Inject 18 | private LocaleDiscovery localeDiscovery; 19 | 20 | @SuppressWarnings("serial") 21 | public void startPayment() { 22 | Locale currentLocale = localeDiscovery.discovery(); 23 | Instance paymentSelected = null; 24 | 25 | if (currentLocale.equals(BRAZIL)) { 26 | paymentSelected = payments.select(new AnnotationLiteral() {}); 27 | } else { 28 | paymentSelected = payments.select(new AnnotationLiteral() {}); 29 | } 30 | 31 | Payment payment = paymentSelected.get(); 32 | payment.pay(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/java/com/craftcoder/cdi/alternatives/PaymentServiceWithAlternatives.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.alternatives; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class PaymentServiceWithAlternatives { 6 | 7 | @Inject 8 | private Payment payment; 9 | 10 | public void startPayment() { 11 | payment.pay(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /cdi-alternatives/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | com.craftcoder.cdi.alternatives.PayPalPayment 10 | 11 | 12 | -------------------------------------------------------------------------------- /cdi-injection-point/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /cdi-injection-point/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-injection-point 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-injection-point 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-injection-point/src/main/java/com/craftcoder/cdi/injectionpoint/Checkout.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.injectionpoint; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class Checkout { 6 | 7 | @Inject 8 | private Payment payment; 9 | 10 | @Inject 11 | private Logger logger; 12 | 13 | public void finishCheckout() { 14 | logger.log("Finishing Checkout"); 15 | 16 | payment.start(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /cdi-injection-point/src/main/java/com/craftcoder/cdi/injectionpoint/Logger.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.injectionpoint; 2 | 3 | public class Logger { 4 | 5 | private Class clazz; 6 | 7 | public Logger(Class clazz) { 8 | this.clazz = clazz; 9 | } 10 | 11 | public void log(String messageToLog) { 12 | System.out.println("Class: " + clazz.getSimpleName() + " :: " + messageToLog); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-injection-point/src/main/java/com/craftcoder/cdi/injectionpoint/LoggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.injectionpoint; 2 | 3 | import javax.enterprise.inject.Produces; 4 | import javax.enterprise.inject.spi.InjectionPoint; 5 | 6 | public class LoggerFactory { 7 | 8 | @Produces 9 | public Logger createLogger(InjectionPoint ip) { 10 | Class clazz = ip.getMember().getDeclaringClass(); 11 | 12 | return new Logger(clazz); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-injection-point/src/main/java/com/craftcoder/cdi/injectionpoint/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.injectionpoint; 2 | 3 | import javax.enterprise.inject.spi.CDI; 4 | 5 | import org.jboss.weld.environment.se.Weld; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) { 10 | try (CDI container = new Weld().initialize()) { 11 | Checkout checkout = container.select(Checkout.class).get(); 12 | 13 | checkout.finishCheckout(); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cdi-injection-point/src/main/java/com/craftcoder/cdi/injectionpoint/Payment.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.injectionpoint; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class Payment { 6 | 7 | @Inject 8 | private Logger mylogger; 9 | 10 | public void start() { 11 | mylogger.log("Starting the Payment"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /cdi-injection-point/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /cdi-interceptors/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /cdi-interceptors/README.md: -------------------------------------------------------------------------------- 1 | Hey! If you are interested in how and why to use CDI Alternatives, just follow the article below from Craft Coder Site 2 | 3 | - [CDI Interceptors](http://craft-coder.com/cdi-interceptors-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-interceptors&utm_term=cdi-java) 4 | 5 | # CDI Guides and Tutorials 6 | 7 | This GitHub Repository belogs to [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) founded by [@alexandregama](https://github.com/alexandregama), that has many **Articles**, **Guides** and **Tutorials** about many frameworks and libraries like: 8 | 9 | - [CDI](http://craft-coder.com/cdi-guides-posts-news-and-tutorials/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) 10 | - [JUnit](http://craft-coder.com/junit-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=junit-java) 11 | - [Mockito](http://craft-coder.com/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=mockito-java) 12 | 13 | If you are interested in **CDI Articles**, you can learn a lot of **CDI Features** in the following links :) 14 | 15 | - [CDI Qualifiers Tutorial](http://craft-coder.com/cdi-qualifiers-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 16 | - [CDI Observers and Events Tutorial](http://craft-coder.com/cdi-events-and-observers-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 17 | - [CDI Lazy Initialization Tutorial](http://craft-coder.com/cdi-lazy-initialization-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 18 | - [CDI How to use Interceptors](http://craft-coder.com/cdi-interceptors-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 19 | - [CDI Alternatives Tutorial](http://craft-coder.com/cdi-alternatives-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 20 | - [CDI How to use Decorators](http://craft-coder.com/cdi-decorators-dependency-injection-java-tutorial/?utm_source=github&utm_medium=cdi-tutorial-guide&utm_term=cdi-java) 21 | 22 | # JUnit Guides and Tutorials 23 | 24 | Are you interested in learn about **JUnit Framework**? Maybe you would like to see a lot of great JUnit Features in [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) in the following links: 25 | 26 | - [JUnit Main Page](http://craft-coder.com/junit-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=junit-tutorial-home&utm_term=junit-java) 27 | - [GitHub Main Page](https://github.com/craft-coder/junit-guides-tutorials) 28 | 29 | ### Articles and Tutorials about JUnit 30 | 31 | - [JUnit - How to Configure JUnit 4 and JUnit 5](http://craft-coder.com/junit-tutorial-how-to-configuration-junit4-and-junit5/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 32 | - [JUnit - Mastering JUnit Assertions](http://craft-coder.com/junit-tutorial-mastering-junit-assertions-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 33 | - [JUnit - How to Use Hamcrest Assertions](http://craft-coder.com/junit-tutorial-hamcrest-assertions-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 34 | - [JUnit - How to work with Tests in Suite](http://craft-coder.com/junit-tutorial-tests-in-suite-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 35 | - [JUnit - How to Order your Execution Test](http://craft-coder.com/junit-tutorial-test-execution-order-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 36 | - [JUnit - Testing with Exceptions](http://craft-coder.com/junit-tutorial-testing-exceptions-java-guide/?utm_source=github&utm_medium=junit-tutorial-guide&utm_term=junit-java) 37 | 38 | # Mockito Guides and Tutorials 39 | 40 | **Mockito** is one of the best **Java Libraries** to work with **Unit and Integration Testing**! In the [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-guide-tutorials&utm_term=cdi-java) you can follow a lot of [Mockito Articles and Tutorials](http://craft-coder.com/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=mockito-tutorial-home&utm_term=mockito-java)! Have fun \o/ 41 | 42 | - [Mockito Main Page](http://craft-coder.com/mockito-guides-tutorials-blog-posts-and-news/?utm_source=github&utm_medium=mockito-tutorial-home&utm_term=mockito-java) 43 | - [GitHub Main Page](https://github.com/craft-coder/mockito-guide-tutorials) 44 | 45 | ### Articles and Tutorials about Mockito 46 | 47 | - [Mockito - Mocking objects by using mock() and verify()](http://craft-coder.com/mockito-tutorial-mocking-objects-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 48 | - [Mockito - Basic usage of when() and thenReturn() methods](http://craft-coder.com/mockito-tutorial-basic-usage-of-when-and-then-return-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 49 | - [Mockito - Throwing Exceptions by using thenThrow()](http://craft-coder.com/mockito-tutorial-throwing-exceptions-then-throw-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 50 | - [Mockito - Stubying with Fluent Interface](http://craft-coder.com/mockito-tutorial-stubbing-with-fluent-interface-java-guide/) 51 | - [Mockito - Printing Custom Message when the Verify fails](http://craft-coder.com/mockito-tutorial-printing-custom-message-when-the-verify-fails-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 52 | - [Mockito BDD - Behavior Driven Development with Mockito](http://craft-coder.com/mockito-tutorial-bdd-behavior-driven-development-with-mockito-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 53 | - [Mockito - Ignoring Stubs](http://craft-coder.com/mockito-tutorial-ignoring-stubs-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 54 | - [Mockito - Reseting Mock Interactions](http://craft-coder.com/mockito-tutorial-resetting-mock-interactions-java-guide/?utm_source=github&utm_medium=mockito-tutorial-guide&utm_term=mockito-java) 55 | 56 | # About the Author 57 | 58 | - [Twitter](https://twitter.com/alexandregamma) 59 | - [GitHub](https://github.com/alexandregama) 60 | - [Linkedin](https://www.linkedin.com/in/alexandregama/) 61 | - [Instagram](https://www.instagram.com/alexandregama/) 62 | - [Google+](https://plus.google.com/+AlexandreGamaLima) 63 | - [About.me](https://about.me/alexandregama) 64 | -------------------------------------------------------------------------------- /cdi-interceptors/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-interceptors 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-interceptors 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/Auditable.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.interceptor.InterceptorBinding; 9 | 10 | @InterceptorBinding 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.TYPE, ElementType.METHOD}) 13 | public @interface Auditable { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/Auditor.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | public class Auditor { 4 | 5 | public void audit() { 6 | System.out.println("Auditing"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/AuditorInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import javax.inject.Inject; 4 | import javax.interceptor.AroundInvoke; 5 | import javax.interceptor.Interceptor; 6 | import javax.interceptor.InvocationContext; 7 | 8 | @Interceptor @Auditable 9 | public class AuditorInterceptor { 10 | 11 | @Inject 12 | private Auditor auditor; 13 | 14 | @AroundInvoke 15 | public Object audit(InvocationContext ic) throws Exception { 16 | auditor.audit(); 17 | 18 | Object result = ic.proceed(); 19 | 20 | return result; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/Checkout.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | public class Checkout { 4 | 5 | @Auditable @Loggable(message = "Finishing Checkout") 6 | public void finishCheckout() { 7 | // your awesome business logic here 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/Loggable.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.enterprise.util.Nonbinding; 9 | import javax.interceptor.InterceptorBinding; 10 | 11 | @InterceptorBinding 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({ElementType.TYPE, ElementType.METHOD}) 14 | public @interface Loggable { 15 | 16 | @Nonbinding String message() default "Logging"; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/LoggerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import javax.inject.Inject; 4 | import javax.interceptor.AroundInvoke; 5 | import javax.interceptor.Interceptor; 6 | import javax.interceptor.InvocationContext; 7 | 8 | @Interceptor @Loggable 9 | public class LoggerInterceptor { 10 | 11 | @Inject 12 | private MyLogger logger; 13 | 14 | @AroundInvoke 15 | public Object log(InvocationContext ic) throws Exception { 16 | Loggable annotation = ic.getMethod().getAnnotation(Loggable.class); 17 | String messageToBeLogged = annotation.message(); 18 | 19 | logger.log(messageToBeLogged); 20 | 21 | Object result = ic.proceed(); 22 | 23 | return result; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import javax.enterprise.inject.spi.CDI; 4 | 5 | import org.jboss.weld.environment.se.Weld; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) { 10 | try (CDI container = new Weld().initialize()) { 11 | Checkout checkout = container.select(Checkout.class).get(); 12 | 13 | checkout.finishCheckout(); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/java/com/hackingcode/cdi/produces/MyLogger.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | public class MyLogger { 4 | 5 | public void log(String message) { 6 | System.out.println(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /cdi-interceptors/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | com.hackingcode.cdi.produces.AuditorInterceptor 10 | com.hackingcode.cdi.produces.LoggerInterceptor 11 | 12 | 13 | -------------------------------------------------------------------------------- /cdi-lazy-injection/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /cdi-lazy-injection/1: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-lazy-injection 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-lazy-injection 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-lazy-injection/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-lazy-injection 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-lazy-injection 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/Buyer.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class Buyer { 4 | 5 | private String email; 6 | 7 | public Buyer(String email) { 8 | this.email = email; 9 | } 10 | 11 | public String getEmail() { 12 | return email; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/Checkout.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | import javax.enterprise.inject.Instance; 4 | import javax.inject.Inject; 5 | 6 | public class Checkout { 7 | 8 | @Inject 9 | private Instance emailSender; 10 | 11 | @Inject 12 | private MetricCreator metricCreator; 13 | 14 | public void finishCheckout(User user) { 15 | System.out.println("Finishing Checkout"); 16 | 17 | if (user.isOptIn()) { //yes, just Optin users! 18 | emailSender.get().sendEmailFor(user); 19 | } 20 | 21 | metricCreator.createMetric(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/CheckoutEvent.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class CheckoutEvent { 4 | 5 | private Order order; 6 | 7 | public CheckoutEvent(Order order) { 8 | this.order = order; 9 | } 10 | 11 | public Order getOrder() { 12 | return order; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/EmailSender.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class EmailSender { 4 | 5 | public EmailSender() { 6 | System.out.println("Constructing the EmailSender"); 7 | } 8 | 9 | public void sendEmailFor(User user) { 10 | System.out.println("Sending email to: " + user.getEmail()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | import javax.enterprise.inject.spi.CDI; 4 | 5 | import org.jboss.weld.environment.se.Weld; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) { 10 | try (CDI container = new Weld().initialize()) { 11 | Checkout checkout = container.select(Checkout.class).get(); 12 | 13 | User user = new User("welcome@craft-coder.com", false); // Now user is not OptIn :( 14 | 15 | checkout.finishCheckout(user); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/MetricCreator.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class MetricCreator { 4 | 5 | public MetricCreator() { 6 | System.out.println("Constructing the MetricCreator"); 7 | } 8 | 9 | public void createMetric() { 10 | System.out.println("Creating new Metric for the new Checkout"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/Order.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class Order { 4 | 5 | private double price; 6 | private Long id; 7 | private Buyer buyer; 8 | 9 | public Order(Buyer buyer, Long id, double price) { 10 | this.buyer = buyer; 11 | this.id = id; 12 | this.price = price; 13 | } 14 | 15 | public double getPrice() { 16 | return price; 17 | } 18 | 19 | public Long getId() { 20 | return id; 21 | } 22 | 23 | public Buyer getBuyer() { 24 | return buyer; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/java/com/craftcoder/cdi/produces/User.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class User { 4 | 5 | private String email; 6 | private boolean optIn; 7 | 8 | public User(String email, boolean optIn) { 9 | this.email = email; 10 | this.optIn = optIn; 11 | } 12 | 13 | public String getEmail() { 14 | return this.email; 15 | } 16 | 17 | public boolean isOptIn() { 18 | return this.optIn; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /cdi-lazy-injection/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /cdi-observers-events/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /cdi-observers-events/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-observers-events 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-observers-events 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/java/com/craftcoder/cdi/produces/Buyer.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class Buyer { 4 | 5 | private String email; 6 | 7 | public Buyer(String email) { 8 | this.email = email; 9 | } 10 | 11 | public String getEmail() { 12 | return email; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/java/com/craftcoder/cdi/produces/Checkout.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | import javax.enterprise.event.Event; 4 | import javax.inject.Inject; 5 | 6 | public class Checkout { 7 | 8 | @Inject 9 | private Event event; 10 | 11 | public void finishCheckout(Order order) { 12 | System.out.println("Finishing Checkout with Id: " + order.getId()); 13 | 14 | event.fire(new CheckoutEvent(order)); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/java/com/craftcoder/cdi/produces/CheckoutEvent.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class CheckoutEvent { 4 | 5 | private Order order; 6 | 7 | public CheckoutEvent(Order order) { 8 | this.order = order; 9 | } 10 | 11 | public Order getOrder() { 12 | return order; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/java/com/craftcoder/cdi/produces/EmailSender.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | import javax.enterprise.event.Observes; 4 | 5 | public class EmailSender { 6 | 7 | public void sendEmailFor(@Observes CheckoutEvent event) { 8 | Buyer buyer = event.getOrder().getBuyer(); 9 | 10 | System.out.println("Sending email to: " + buyer.getEmail()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/java/com/craftcoder/cdi/produces/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | import javax.enterprise.inject.spi.CDI; 4 | 5 | import org.jboss.weld.environment.se.Weld; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) { 10 | try (CDI container = new Weld().initialize()) { 11 | Checkout checkout = container.select(Checkout.class).get(); 12 | 13 | Buyer buyer = new Buyer("welcome@craft-coder.com"); 14 | Order order = new Order(buyer, 10L, 80.0); 15 | 16 | checkout.finishCheckout(order); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/java/com/craftcoder/cdi/produces/MetricCreator.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | import javax.enterprise.event.Observes; 4 | 5 | public class MetricCreator { 6 | 7 | public void createMetricFor(@Observes CheckoutEvent event) { 8 | Order order = event.getOrder(); 9 | 10 | System.out.println("Creating new Metric for OrderId: " + order.getId()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/java/com/craftcoder/cdi/produces/Order.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.produces; 2 | 3 | public class Order { 4 | 5 | private double price; 6 | private Long id; 7 | private Buyer buyer; 8 | 9 | public Order(Buyer buyer, Long id, double price) { 10 | this.buyer = buyer; 11 | this.id = id; 12 | this.price = price; 13 | } 14 | 15 | public double getPrice() { 16 | return price; 17 | } 18 | 19 | public Long getId() { 20 | return id; 21 | } 22 | 23 | public Buyer getBuyer() { 24 | return buyer; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cdi-observers-events/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /cdi-produces/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /cdi-produces/README.md: -------------------------------------------------------------------------------- 1 | # CDI Produces Annotation 2 | 3 | Hello! 4 | 5 | This source code is part of the [CDI Guide](http://craft-coder.com/cdi-produces-annotation-java-tutorial/?utm_source=github&utm_medium=cdi-produces&utm_term=cdi) from [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-produces&utm_term=cdi) 6 | 7 | In this tutorial, we will going to see an example of how to use CDI @Produces Annotation 8 | 9 | Enjoy! 10 | -------------------------------------------------------------------------------- /cdi-produces/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-produces 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-produces 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-produces/src/main/java/com/hackingcode/cdi/produces/AwesomeLoggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import javax.enterprise.inject.Produces; 4 | 5 | public class AwesomeLoggerFactory { 6 | 7 | @Produces 8 | public SpecialLogger createLogger() { 9 | LogConfiguration logInDebugMode = new LogConfiguration(true, false); 10 | 11 | return new SpecialLogger(logInDebugMode); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /cdi-produces/src/main/java/com/hackingcode/cdi/produces/Checkout.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class Checkout { 6 | 7 | @Inject 8 | private SpecialLogger logger; 9 | 10 | public void finishCheckout() { 11 | logger.log("Finishing Checkout"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /cdi-produces/src/main/java/com/hackingcode/cdi/produces/LogConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | public class LogConfiguration { 4 | 5 | private boolean infoMode; 6 | 7 | private boolean debugMode; 8 | 9 | public LogConfiguration(boolean infoMode, boolean debugMode) { 10 | this.infoMode = infoMode; 11 | this.debugMode = debugMode; 12 | } 13 | 14 | public boolean isInInfoMode() { 15 | return infoMode; 16 | } 17 | 18 | public boolean isInDebugMode() { 19 | return debugMode; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /cdi-produces/src/main/java/com/hackingcode/cdi/produces/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | import javax.enterprise.inject.spi.CDI; 4 | 5 | import org.jboss.weld.environment.se.Weld; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) { 10 | try (CDI container = new Weld().initialize()) { 11 | Checkout checkout = container.select(Checkout.class).get(); 12 | 13 | checkout.finishCheckout(); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cdi-produces/src/main/java/com/hackingcode/cdi/produces/SpecialLogger.java: -------------------------------------------------------------------------------- 1 | package com.hackingcode.cdi.produces; 2 | 3 | public class SpecialLogger { 4 | 5 | private LogConfiguration configuration; 6 | 7 | public SpecialLogger(LogConfiguration configuration) { 8 | this.configuration = configuration; 9 | } 10 | 11 | public void log(String message) { 12 | if (configuration.isInDebugMode()) { 13 | System.out.println("DEBUG LOG: " + message); 14 | } 15 | else if (configuration.isInInfoMode()) { 16 | System.out.println("DEBUG LOG: " + message); 17 | } else { 18 | System.out.println("DEFAULT LOG: " + message); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /cdi-produces/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /cdi-qualifiers/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | build/ 3 | .classpath 4 | .project 5 | .settings 6 | -------------------------------------------------------------------------------- /cdi-qualifiers/README.md: -------------------------------------------------------------------------------- 1 | # CDI Qualifiers 2 | 3 | Hello! 4 | 5 | This source code is part of the [CDI Guide](http://craft-coder.com/cdi-produces-annotation-java-tutorial/?utm_source=github&utm_medium=cdi-produces&utm_term=cdi) from [Craft Coder Site](http://craft-coder.com/?utm_source=github&utm_medium=cdi-produces&utm_term=cdi) 6 | 7 | In this tutorial, we will going to see an example of how to use CDI Qualifiers 8 | 9 | Enjoy! 10 | -------------------------------------------------------------------------------- /cdi-qualifiers/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-qualifiers 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-qualifiers 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/AwesomeLogger.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | public class AwesomeLogger { 4 | 5 | private LogConfiguration configuration; 6 | 7 | public AwesomeLogger(LogConfiguration configuration) { 8 | this.configuration = configuration; 9 | } 10 | 11 | public void log(String message) { 12 | if (configuration.isInDebugMode()) { 13 | System.out.println("DEBUG LOG: " + message); 14 | } 15 | else if (configuration.isInInfoMode()) { 16 | System.out.println("INFO LOG: " + message); 17 | } else if (configuration.isInWarnMode()) { 18 | System.out.println("WARN LOG: " + message); 19 | } else { 20 | System.out.println("DEFAULT LOG: " + message); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/AwesomeLoggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | import javax.enterprise.inject.Produces; 4 | 5 | public class AwesomeLoggerFactory { 6 | 7 | @Produces @LoggerMode(desiredMode = Mode.DEBUG) 8 | public AwesomeLogger createDebugLogger() { //yes, I renamed it 9 | boolean debugMode = true; //just to be clear that the debug mode is on 10 | LogConfiguration logInDebugMode = new LogConfiguration(false, debugMode, false); 11 | 12 | return new AwesomeLogger(logInDebugMode); 13 | } 14 | 15 | @Produces @LoggerMode(desiredMode = Mode.INFO) 16 | public AwesomeLogger createInfoLogger() { //new method here :) 17 | boolean infoMode = true; 18 | LogConfiguration logInInfoMode = new LogConfiguration(infoMode, false, false); 19 | 20 | return new AwesomeLogger(logInInfoMode); 21 | } 22 | 23 | @Produces @LoggerMode(desiredMode = Mode.WARN) 24 | public AwesomeLogger createWarnLogger() { //new method here :) 25 | boolean warnMode = true; 26 | LogConfiguration logInWarnMode = new LogConfiguration(false, false, warnMode); 27 | 28 | return new AwesomeLogger(logInWarnMode); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/Checkout.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | import javax.inject.Inject; 4 | 5 | public class Checkout { 6 | 7 | @Inject @LoggerMode(desiredMode = Mode.DEBUG) 8 | private AwesomeLogger logger; 9 | 10 | public void finishCheckout() { 11 | logger.log("Finishing Checkout"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/DebugMode.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.inject.Qualifier; 9 | 10 | @Qualifier 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.METHOD, ElementType.FIELD}) 13 | public @interface DebugMode { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/InfoMode.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.inject.Qualifier; 9 | 10 | @Qualifier 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.METHOD, ElementType.FIELD}) 13 | public @interface InfoMode { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/LogConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | public class LogConfiguration { 4 | 5 | private boolean infoMode; 6 | 7 | private boolean debugMode; 8 | 9 | private boolean warnMode; 10 | 11 | public LogConfiguration(boolean infoMode, boolean debugMode, boolean warnMode) { 12 | this.infoMode = infoMode; 13 | this.debugMode = debugMode; 14 | this.warnMode = warnMode; 15 | } 16 | 17 | public boolean isInInfoMode() { 18 | return infoMode; 19 | } 20 | 21 | public boolean isInDebugMode() { 22 | return debugMode; 23 | } 24 | 25 | public boolean isInWarnMode() { 26 | return warnMode; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/LoggerMode.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.inject.Qualifier; 9 | 10 | @Qualifier 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.METHOD, ElementType.FIELD}) 13 | public @interface LoggerMode { 14 | 15 | Mode desiredMode(); 16 | 17 | } 18 | 19 | enum Mode { 20 | 21 | DEBUG, INFO, WARN 22 | 23 | } -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | import javax.enterprise.inject.spi.CDI; 4 | 5 | import org.jboss.weld.environment.se.Weld; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) { 10 | try (CDI container = new Weld().initialize()) { 11 | Checkout checkout = container.select(Checkout.class).get(); 12 | 13 | checkout.finishCheckout(); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/java/com/craftcoder/cdi/qualifiers/WarnMode.java: -------------------------------------------------------------------------------- 1 | package com.craftcoder.cdi.qualifiers; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.inject.Qualifier; 9 | 10 | @Qualifier 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.METHOD, ElementType.FIELD}) 13 | public @interface WarnMode { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cdi-qualifiers/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.craftcoder.cdi 6 | cdi-guide-tutorials 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cdi-guide-tutorials 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.hamcrest 21 | hamcrest-all 22 | 1.3 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.12 29 | test 30 | 31 | 32 | 33 | 34 | org.jboss.weld.se 35 | weld-se-core 36 | 3.0.0.Alpha16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-eclipse-plugin 46 | 47 | true 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | --------------------------------------------------------------------------------