8000 GitHub - chriniko13/cdi-training
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chriniko13/cdi-training

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cdi-demo

Project Description

This project has been created and used from me to train/onboard mid-to-senior level engineers in the CDI with the usage of Quarkus framework.

It explores basic CDI stuff but goes also in more depth in some specific topics.

Topics covered in the seminar + project:

  • What is Dependency Injection (DI) ?
  • How we can create just a basic DI framework ?
  • What is CDI Bean == Bean
  • CDI Scopes and Contexts

    Diagram 1:
    
         [Thread] ---> [ProxyBean] ---> [Bean]
         
         
    Diagram 2:
    
          [Context] --- gets accessed from multiple ---> [Thread] (eg: is that scope active for that thread ?)
                \
                 \ 
                   --- has a ---> [Scope] ---which manages multiple---> [BeanInstance] (eg: managing all bean instances of this scope)        
  • CDI qualifiers
  • CDI Events
  • CDI Producers
  • Decorators and Interceptors
  • Dynamic Beans
    Notes on Dynamic Beans
    -----------------------------
    
    Manually implementing a Bean<T>


    1. we need to define the Contextual
            public interface Contextual<T> {
   
                public T create(CreationalContext<T> creationalContext);

                public void destroy(T instance, CreationalContext<T> creationalContext);
            }
            
    2. The Core Attributes (Bean Attributes)
        - Types
        - Qualifier
        - Name
        - Scope
        - Stereotypes
        - Alternative (a boolean indicating the bean is an alternative or not)

            public interface BeanAttributes<T> {

                public Set<Type> getTypes();
            
                public Set<Annotation> getQualifiers();
            
                public Class<? extends Annotation> getScope();
            
                public String getName();
            
                public Set<Class<? extends Annotation>> getStereotypes();
            
                public boolean isAlternative();
            }
            
            
    3. The Bean, which combines the Contextual and the BeanAttributes defined on the above steps
            public interface Bean<T> extends Contextual<T>, BeanAttributes<T> {

                public Class<?> getBeanClass();
            
                public Set<InjectionPoint> getInjectionPoints();
            }

    4. The PassivationCapable interface
    
    
    5. Now, we can add the DynamicBean by using CDI Extensions or Configurator
    
    

Quarkus Details

This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .

Quarkus Cheat Sheet

https://lordofthejars.github.io/quarkus-cheat-sheet/

Running the application in dev mode

You can run your application in dev mode that enables live coding using:

./mvnw compile quarkus:dev

NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.

Packaging and running the application

The application can be packaged using:

./mvnw package

It produces the quarkus-run.jar file in the target/quarkus-app/ directory. Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/ directory.

The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar.

If you want to build an über-jar, execute the following command:

./mvnw package -Dquarkus.package.type=uber-jar

The application, packaged as an über-jar, is now runnable using java -jar target/*-runner.jar.

Creating a native executable

You can create a native executable using:

./mvnw package -Pnative

Or, if you don't have GraalVM installed, you can run the native executable build in a container using:

./mvnw package -Pnative -Dquarkus.native.container-build=true

You can then execute your native executable with: ./target/cdi-demo-1.0-SNAPSHOT-runner

If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.

Related Guides

  • Logging GELF (guide): Log using the Graylog Extended Log Format and centralize your logs in ELK or EFK
  • YAML Configuration (guide): Use YAML to configure your Quarkus application
  • RESTEasy Classic (guide): REST endpoint framework implementing Jakarta REST and more

Provided Code

YAML Config

Configure your application with YAML

Related guide section...

The Quarkus application configuration is located in src/main/resources/application.yml.

RESTEasy JAX-RS

Easily start your RESTful Web Services

Related guide section...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0