├── .gitignore
├── README.md
├── bootique-rest
├── assembly.xml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── objectstyle
│ │ └── bootique
│ │ └── rest
│ │ ├── Api.java
│ │ ├── Main.java
│ │ └── MainModule.java
│ └── resources
│ └── META-INF
│ └── services
│ └── io.bootique.BQModule
├── bootique
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── objectstyle
│ │ └── bootique
│ │ ├── Main.java
│ │ ├── MainCommand.java
│ │ └── MainModule.java
│ └── resources
│ └── META-INF
│ └── services
│ └── io.bootique.BQModule
├── cayennedi
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── objectstyle
│ └── cayenne
│ ├── Main.java
│ ├── MainModule.java
│ └── SubServiceProvider.java
├── common
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── objectstyle
│ └── di
│ └── service
│ ├── Meter.java
│ ├── Service.java
│ ├── ServiceImpl.java
│ ├── SubService.java
│ └── SubServiceImpl.java
├── dagger
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── objectstyle
│ └── dagger
│ ├── Main.java
│ ├── MainModule.java
│ └── Root.java
├── guice
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── objectstyle
│ └── guice
│ ├── Main.java
│ └── MainModule.java
├── owb
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── objectstyle
│ └── owb
│ ├── Main.java
│ └── MainModule.java
├── pom.xml
├── results1_1.ods
├── spring
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── objectstyle
│ └── spring
│ └── Main.java
├── springboot-rest
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── objectstyle
│ └── springboot
│ ├── Api.java
│ ├── Config.java
│ └── Main.java
└── springboot
├── pom.xml
└── src
└── main
└── java
└── org
└── objectstyle
└── springboot
├── Config.java
├── Main.java
└── Runner.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .idea
3 | target
4 | dependency-reduced-pom.xml
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DI Containers Comparision
2 |
3 | Comparing a simple app varieties on different DI containers.
4 |
5 | ## IntelliJ IDEA Setup
6 |
7 | Go to "Preferences > Annotation Processors", and check "Enable Annotation
8 | Processing".
9 |
10 | ## "Benchmark"
11 |
12 | ```
13 | # Build (can't compare build times, as module ordering affects the results)
14 | mvn clean package
15 | ```
16 |
17 | ### File sizes
18 | ```
19 | find . -name '*.jar' |xargs ls -l |grep -v original |grep -v common
20 | ```
21 |
22 | ### Execution time
23 | ```
24 | time java -jar ./bootique/target/bootique-*.jar
25 | time java -jar ./cayennedi/target/cayennedi-*.jar
26 | time java -jar ./dagger/target/dagger-*.jar
27 | time java -jar ./guice/target/guice-*.jar
28 | time java -jar ./owb/target/owb-*.jar
29 | time java -jar ./spring/target/spring-*.jar
30 | time java -jar ./springboot/target/springboot-*.jar
31 | ```
32 |
33 | ## Results (Java 21)
34 | _MacBook Pro 2021 M1, 16GB RAM, OpenJDK Temurin-21+35_
35 |
36 | |DI| Jar w/Deps Size, KB | :arrow_down: Exec time, ms |
37 | |----|---------------------|----------------------------|
38 | |Dagger| 58 | 90 |
39 | |Cayenne DI| 71 | 105 |
40 | |Bootique| 2894 | 157 |
41 | |Guice| 3827 | 204 |
42 | |OpenWebBeans| 1632 | ? (failures) |
43 | |Spring| 4800 | 221 |
44 | |Spring Boot| 10094 | 743 |
45 |
--------------------------------------------------------------------------------
/bootique-rest/assembly.xml:
--------------------------------------------------------------------------------
1 |
3 | tar.gz
4 |
5 | tar.gz
6 |
7 |
8 |
9 | ${project.build.directory}
10 | true
11 | ./
12 |
13 | ${project.artifactId}-${project.version}.jar
14 | lib/
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/bootique-rest/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | bootique-rest
14 | jar
15 |
16 |
17 | org.objectstyle.bootique.rest.Main
18 |
19 |
20 |
21 |
22 |
23 | io.bootique.bom
24 | bootique-bom
25 | ${bootique.version}
26 | import
27 | pom
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.objectstyle.di
35 | common
36 | ${project.version}
37 |
38 |
39 | io.bootique.jersey
40 | bootique-jersey-jakarta
41 |
42 |
43 | io.bootique.logback
44 | bootique-logback
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | maven-jar-plugin
53 |
54 |
55 |
56 | ${main.class}
57 | true
58 | lib/
59 | false
60 | false
61 |
62 |
63 |
64 |
65 |
66 | maven-dependency-plugin
67 |
68 | runtime
69 | ${project.build.directory}/lib
70 |
71 |
72 |
73 | assembly
74 | prepare-package
75 |
76 | copy-dependencies
77 |
78 |
79 |
80 |
81 |
82 | org.apache.maven.plugins
83 | maven-assembly-plugin
84 | 3.1.1
85 |
86 | false
87 |
88 | assembly.xml
89 |
90 | posix
91 |
92 |
93 |
94 | assembly
95 | package
96 |
97 | single
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/bootique-rest/src/main/java/org/objectstyle/bootique/rest/Api.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.bootique.rest;
2 |
3 | import jakarta.ws.rs.GET;
4 | import jakarta.ws.rs.Path;
5 | import jakarta.ws.rs.Produces;
6 | import jakarta.ws.rs.core.MediaType;
7 | import org.objectstyle.di.service.Meter;
8 | import org.objectstyle.di.service.Service;
9 |
10 | import javax.inject.Inject;
11 |
12 | @Path("")
13 | public class Api {
14 |
15 | @Inject
16 | Service service;
17 |
18 | @GET
19 | @Produces(MediaType.TEXT_PLAIN)
20 | public String get() {
21 | Meter.runMetrics();
22 | return service.doIt();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/bootique-rest/src/main/java/org/objectstyle/bootique/rest/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.bootique.rest;
2 |
3 | import io.bootique.Bootique;
4 |
5 | import java.lang.management.ManagementFactory;
6 | import java.time.LocalDateTime;
7 |
8 | public class Main {
9 |
10 | public static void main(String[] args) {
11 | // measuring JVM start time
12 | System.out.println(ManagementFactory.getRuntimeMXBean().getUptime());
13 |
14 | // timestamping the app start point
15 | System.out.println(LocalDateTime.now());
16 |
17 | Bootique.app(args).autoLoadModules().exec().exit();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/bootique-rest/src/main/java/org/objectstyle/bootique/rest/MainModule.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.bootique.rest;
2 |
3 | import io.bootique.BQCoreModule;
4 | import io.bootique.BQModule;
5 | import io.bootique.BaseModule;
6 | import io.bootique.di.Binder;
7 | import io.bootique.di.Provides;
8 | import io.bootique.jersey.JerseyModule;
9 | import io.bootique.jetty.command.ServerCommand;
10 | import org.objectstyle.di.service.Service;
11 | import org.objectstyle.di.service.ServiceImpl;
12 | import org.objectstyle.di.service.SubService;
13 | import org.objectstyle.di.service.SubServiceImpl;
14 |
15 | import javax.inject.Singleton;
16 |
17 | public class MainModule implements BQModule {
18 |
19 | @Override
20 | public void configure(Binder binder) {
21 | BQCoreModule.extend(binder).setDefaultCommand(ServerCommand.class);
22 | JerseyModule.extend(binder).addResource(Api.class);
23 | }
24 |
25 | @Provides
26 | @Singleton
27 | Service provideService(SubService subService) {
28 | return new ServiceImpl(subService);
29 | }
30 |
31 | @Provides
32 | @Singleton
33 | SubService provideSubService() {
34 | return new SubServiceImpl();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/bootique-rest/src/main/resources/META-INF/services/io.bootique.BQModule:
--------------------------------------------------------------------------------
1 | org.objectstyle.bootique.rest.MainModule
--------------------------------------------------------------------------------
/bootique/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | bootique
14 | jar
15 |
16 |
17 | org.objectstyle.bootique.Main
18 |
19 |
20 |
21 |
22 |
23 | io.bootique.bom
24 | bootique-bom
25 | ${bootique.version}
26 | import
27 | pom
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.objectstyle.di
35 | common
36 | ${project.version}
37 |
38 |
39 | io.bootique
40 | bootique
41 |
42 |
43 |
44 |
45 |
46 |
47 | maven-shade-plugin
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/bootique/src/main/java/org/objectstyle/bootique/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.bootique;
2 |
3 | import io.bootique.Bootique;
4 |
5 | public class Main {
6 |
7 | public static void main(String[] args) {
8 | Bootique.app(args).autoLoadModules().exec();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/bootique/src/main/java/org/objectstyle/bootique/MainCommand.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.bootique;
2 |
3 | import io.bootique.cli.Cli;
4 | import io.bootique.command.Command;
5 | import io.bootique.command.CommandOutcome;
6 | import org.objectstyle.di.service.Service;
7 |
8 | import javax.inject.Inject;
9 | import javax.inject.Provider;
10 |
11 | public class MainCommand implements Command {
12 |
13 | private Provider serviceProvider;
14 |
15 | @Inject
16 | public MainCommand(Provider serviceProvider) {
17 | this.serviceProvider = serviceProvider;
18 | }
19 |
20 | @Override
21 | public CommandOutcome run(Cli cli) {
22 | System.out.println(serviceProvider.get().doIt());
23 | // Meter.runMetrics();
24 | return CommandOutcome.succeeded();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/bootique/src/main/java/org/objectstyle/bootique/MainModule.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.bootique;
2 |
3 | import io.bootique.BQCoreModule;
4 | import io.bootique.BQModule;
5 | import io.bootique.BaseModule;
6 | import io.bootique.di.Binder;
7 | import io.bootique.di.Provides;
8 | import org.objectstyle.di.service.Service;
9 | import org.objectstyle.di.service.ServiceImpl;
10 | import org.objectstyle.di.service.SubService;
11 | import org.objectstyle.di.service.SubServiceImpl;
12 |
13 | import javax.inject.Singleton;
14 |
15 | public class MainModule implements BQModule {
16 |
17 | @Override
18 | public void configure(Binder binder) {
19 | BQCoreModule.extend(binder).setDefaultCommand(MainCommand.class);
20 | }
21 |
22 | @Provides
23 | @Singleton
24 | Service provideService(SubService subService) {
25 | return new ServiceImpl(subService);
26 | }
27 |
28 | @Provides
29 | @Singleton
30 | SubService provideSubService() {
31 | return new SubServiceImpl();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/bootique/src/main/resources/META-INF/services/io.bootique.BQModule:
--------------------------------------------------------------------------------
1 | org.objectstyle.bootique.MainModule
--------------------------------------------------------------------------------
/cayennedi/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | cayennedi
14 |
15 | jar
16 |
17 |
18 | org.objectstyle.cayenne.Main
19 |
20 |
21 |
22 |
23 | org.objectstyle.di
24 | common
25 | ${project.version}
26 |
27 |
28 | org.apache.cayenne
29 | cayenne-di
30 | ${cayenne.version}
31 |
32 |
33 |
34 |
35 |
36 |
37 | maven-shade-plugin
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/cayennedi/src/main/java/org/objectstyle/cayenne/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.cayenne;
2 |
3 | import org.apache.cayenne.di.DIBootstrap;
4 | import org.objectstyle.di.service.Service;
5 |
6 | public class Main {
7 |
8 | public static void main(String[] args) {
9 | Service s = DIBootstrap.createInjector(new MainModule()).getInstance(Service.class);
10 | System.out.println(s.doIt());
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/cayennedi/src/main/java/org/objectstyle/cayenne/MainModule.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.cayenne;
2 |
3 | import org.apache.cayenne.di.Binder;
4 | import org.apache.cayenne.di.Module;
5 | import org.objectstyle.di.service.Service;
6 | import org.objectstyle.di.service.SubService;
7 | import org.objectstyle.di.service.SubServiceImpl;
8 |
9 | public class MainModule implements Module {
10 |
11 | @Override
12 | public void configure(Binder binder) {
13 | binder.bind(Service.class).toProvider(SubServiceProvider.class);
14 | binder.bind(SubService.class).to(SubServiceImpl.class);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/cayennedi/src/main/java/org/objectstyle/cayenne/SubServiceProvider.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.cayenne;
2 |
3 | import org.apache.cayenne.di.DIRuntimeException;
4 | import org.apache.cayenne.di.Inject;
5 | import org.apache.cayenne.di.Provider;
6 | import org.objectstyle.di.service.Service;
7 | import org.objectstyle.di.service.ServiceImpl;
8 | import org.objectstyle.di.service.SubService;
9 |
10 | public class SubServiceProvider implements Provider {
11 |
12 | @Inject
13 | private SubService subService;
14 |
15 | @Override
16 | public Service get() throws DIRuntimeException {
17 | return new ServiceImpl(subService);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | common
14 | jar
15 |
16 |
--------------------------------------------------------------------------------
/common/src/main/java/org/objectstyle/di/service/Meter.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.di.service;
2 |
3 |
4 | public class Meter {
5 |
6 | public static void runMetrics() {
7 | System.gc();
8 | System.gc();
9 |
10 | long memory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
11 | System.out.printf("Memory in use, bytes: %s\n", memory);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/common/src/main/java/org/objectstyle/di/service/Service.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.di.service;
2 |
3 |
4 | public interface Service {
5 |
6 | String doIt();
7 | }
8 |
--------------------------------------------------------------------------------
/common/src/main/java/org/objectstyle/di/service/ServiceImpl.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.di.service;
2 |
3 | public class ServiceImpl implements Service {
4 |
5 | private SubService subService;
6 |
7 | public ServiceImpl(SubService subService) {
8 | this.subService = subService;
9 | }
10 |
11 | public String doIt() {
12 | return "ServiceImpl_" + subService.doIt();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/common/src/main/java/org/objectstyle/di/service/SubService.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.di.service;
2 |
3 | public interface SubService {
4 | String doIt();
5 | }
6 |
--------------------------------------------------------------------------------
/common/src/main/java/org/objectstyle/di/service/SubServiceImpl.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.di.service;
2 |
3 | public class SubServiceImpl implements SubService {
4 |
5 | public String doIt() {
6 | return "SubServiceImpl";
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/dagger/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | dagger
14 | jar
15 |
16 |
17 | org.objectstyle.dagger.Main
18 |
19 |
20 |
21 |
22 | org.objectstyle.di
23 | common
24 | ${project.version}
25 |
26 |
27 | com.google.dagger
28 | dagger
29 | ${dagger.version}
30 |
31 |
32 | com.google.dagger
33 | dagger-compiler
34 | ${dagger.version}
35 | provided
36 |
37 |
38 |
39 |
40 |
41 |
42 | maven-shade-plugin
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/dagger/src/main/java/org/objectstyle/dagger/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.dagger;
2 |
3 | public class Main {
4 |
5 | public static void main(String[] args) {
6 | Root r = DaggerRoot.create();
7 | System.out.println(r.service().doIt());
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/dagger/src/main/java/org/objectstyle/dagger/MainModule.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.dagger;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import org.objectstyle.di.service.Service;
6 | import org.objectstyle.di.service.ServiceImpl;
7 | import org.objectstyle.di.service.SubService;
8 | import org.objectstyle.di.service.SubServiceImpl;
9 |
10 | import javax.inject.Singleton;
11 |
12 | @Module
13 | public class MainModule {
14 |
15 | @Provides
16 | @Singleton
17 | Service provideService(SubService subService) {
18 | return new ServiceImpl(subService);
19 | }
20 |
21 | @Provides
22 | @Singleton
23 | SubService provideSubService() {
24 | return new SubServiceImpl();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/dagger/src/main/java/org/objectstyle/dagger/Root.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.dagger;
2 |
3 | import dagger.Component;
4 | import org.objectstyle.di.service.Service;
5 |
6 | import javax.inject.Singleton;
7 |
8 | @Singleton
9 | @Component(modules = MainModule.class)
10 | public interface Root {
11 |
12 | Service service();
13 | }
14 |
--------------------------------------------------------------------------------
/guice/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | guice
14 | jar
15 |
16 |
17 | org.objectstyle.guice.Main
18 |
19 |
20 |
21 |
22 | org.objectstyle.di
23 | common
24 | ${project.version}
25 |
26 |
27 | com.google.inject
28 | guice
29 | ${guice.version}
30 |
31 |
32 |
33 |
34 |
35 |
36 | maven-shade-plugin
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/guice/src/main/java/org/objectstyle/guice/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.guice;
2 |
3 | import com.google.inject.Guice;
4 | import org.objectstyle.di.service.Service;
5 |
6 | public class Main {
7 |
8 | public static void main(String[] args) {
9 | Service s = Guice.createInjector(new MainModule()).getInstance(Service.class);
10 | System.out.println(s.doIt());
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/guice/src/main/java/org/objectstyle/guice/MainModule.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.guice;
2 |
3 | import com.google.inject.Binder;
4 | import com.google.inject.Module;
5 | import com.google.inject.Provides;
6 | import org.objectstyle.di.service.Service;
7 | import org.objectstyle.di.service.ServiceImpl;
8 | import org.objectstyle.di.service.SubService;
9 | import org.objectstyle.di.service.SubServiceImpl;
10 |
11 | import javax.inject.Singleton;
12 |
13 | public class MainModule implements Module {
14 |
15 | @Override
16 | public void configure(Binder binder) {
17 | }
18 |
19 | @Provides
20 | @Singleton
21 | Service provideService(SubService subService) {
22 | return new ServiceImpl(subService);
23 | }
24 |
25 | @Provides
26 | @Singleton
27 | SubService provideSubService() {
28 | return new SubServiceImpl();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/owb/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | owb
14 | jar
15 |
16 |
17 | org.objectstyle.owb.Main
18 |
19 |
20 |
21 | Apache OpenWebBeans is a full featured JavaEE 8 level CDI container.
22 | This is not a trimmed down version but really full EE8...
23 |
24 | More info at https://openwebbeans.apache.org
25 |
26 |
27 |
28 |
29 |
30 | org.objectstyle.di
31 | common
32 | ${project.version}
33 |
34 |
35 |
36 |
37 | org.apache.geronimo.specs
38 | geronimo-annotation_1.3_spec
39 | 1.0
40 |
41 |
42 | org.apache.geronimo.specs
43 | geronimo-atinject_1.0_spec
44 | 1.0
45 |
46 |
47 | org.apache.geronimo.specs
48 | geronimo-jcdi_2.0_spec
49 | 1.0
50 |
51 |
52 | org.apache.geronimo.specs
53 | geronimo-interceptor_1.2_spec
54 | 1.0
55 |
56 |
57 |
58 |
59 | org.apache.openwebbeans
60 | openwebbeans-impl
61 | ${owb.version}
62 |
63 |
64 | org.apache.openwebbeans
65 | openwebbeans-spi
66 | ${owb.version}
67 |
68 |
69 | org.apache.openwebbeans
70 | openwebbeans-se
71 | ${owb.version}
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | maven-shade-plugin
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | org.apache.openwebbeans
89 | openwebbeans-maven
90 | ${owb.maven.version}
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/owb/src/main/java/org/objectstyle/owb/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.owb;
2 |
3 |
4 | import javax.enterprise.inject.se.SeContainer;
5 | import javax.enterprise.inject.se.SeContainerInitializer;
6 | import javax.enterprise.inject.spi.CDI;
7 |
8 | import org.objectstyle.di.service.Service;
9 |
10 | public class Main {
11 |
12 | public static void main(String[] args) {
13 | SeContainer cdiContainer = SeContainerInitializer.newInstance()
14 | .disableDiscovery()
15 | .addBeanClasses(MainModule.class)
16 | .initialize();
17 | Service s = CDI.current().select(Service.class).get();
18 |
19 | System.out.println(s.doIt());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/owb/src/main/java/org/objectstyle/owb/MainModule.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.owb;
2 |
3 | import javax.enterprise.context.ApplicationScoped;
4 | import javax.enterprise.inject.Produces;
5 |
6 | import org.objectstyle.di.service.Service;
7 | import org.objectstyle.di.service.ServiceImpl;
8 | import org.objectstyle.di.service.SubService;
9 | import org.objectstyle.di.service.SubServiceImpl;
10 |
11 | @ApplicationScoped
12 | public class MainModule {
13 |
14 | @Produces
15 | @ApplicationScoped
16 | Service provideService(SubService subService) {
17 | return new ServiceImpl(subService);
18 | }
19 |
20 | @Produces
21 | @ApplicationScoped
22 | SubService provideSubService() {
23 | return new SubServiceImpl();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.objectstyle.di
8 | di-comparison
9 | 1.1-SNAPSHOT
10 |
11 | pom
12 |
13 |
14 | 21
15 | UTF-8
16 | UTF-8
17 |
18 | 3.0-M3
19 | 2.51.1
20 | 5.1.0
21 | 4.2
22 | 4.0.2
23 | 2.0.17
24 | 6.1.5
25 | 3.2.4
26 |
27 |
28 |
29 | common
30 | bootique
31 | bootique-rest
32 | dagger
33 | guice
34 | cayennedi
35 | spring
36 | springboot
37 | springboot-rest
38 | owb
39 |
40 |
41 |
42 |
43 | snapshots
44 | https://maven.objectstyle.org/nexus/content/repositories/linkrest-snapshots
45 |
46 | false
47 |
48 |
49 | true
50 |
51 |
52 |
53 |
54 | central
55 | https://repo1.maven.org/maven2
56 |
57 | true
58 |
59 |
60 | false
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | maven-compiler-plugin
70 | 3.8.1
71 |
72 |
73 | org.apache.maven.plugins
74 | maven-shade-plugin
75 | 3.2.3
76 |
77 |
78 | true
79 |
80 |
81 | *:*
82 |
83 | META-INF/*.SF
84 | META-INF/*.DSA
85 | META-INF/*.RSA
86 |
87 |
88 |
89 |
90 |
91 |
92 | package
93 |
94 | shade
95 |
96 |
97 |
98 |
100 |
102 | ${main.class}
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | org.apache.maven.plugins
112 | maven-jar-plugin
113 | 3.2.0
114 |
115 |
116 |
117 | true
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/results1_1.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andrus/di-comparison/c6c87283cae3a16b95b676019d2c92e0323c21b5/results1_1.ods
--------------------------------------------------------------------------------
/spring/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | spring
14 | jar
15 |
16 |
17 | org.objectstyle.spring.Main
18 |
19 |
20 |
21 |
22 | org.objectstyle.di
23 | common
24 | ${project.version}
25 |
26 |
27 | org.springframework
28 | spring-context
29 | ${spring.version}
30 |
31 |
32 |
33 |
34 |
35 |
36 | maven-shade-plugin
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/spring/src/main/java/org/objectstyle/spring/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.spring;
2 |
3 | import org.objectstyle.di.service.Service;
4 | import org.objectstyle.di.service.ServiceImpl;
5 | import org.objectstyle.di.service.SubService;
6 | import org.objectstyle.di.service.SubServiceImpl;
7 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.stereotype.Component;
10 |
11 | @Component
12 | public class Main {
13 |
14 | @Bean
15 | public Service service(SubService subService) {
16 | return new ServiceImpl(subService);
17 | }
18 |
19 | @Bean
20 | public SubService subService() {
21 | return new SubServiceImpl();
22 | }
23 |
24 | public static void main(String[] args) {
25 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Main.class);
26 | System.out.println(context.getBean(Service.class).doIt());
27 | }
28 | }
--------------------------------------------------------------------------------
/springboot-rest/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | springboot-rest
14 | jar
15 |
16 |
17 | org.objectstyle.springboot.Main
18 |
19 |
20 |
21 |
22 | org.objectstyle.di
23 | common
24 | ${project.version}
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-web
29 | ${springboot.version}
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-tomcat
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-jetty
42 | ${springboot.version}
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-maven-plugin
51 | ${springboot.version}
52 |
53 |
54 |
55 | repackage
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/springboot-rest/src/main/java/org/objectstyle/springboot/Api.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.springboot;
2 |
3 | import org.objectstyle.di.service.Meter;
4 | import org.objectstyle.di.service.Service;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.http.MediaType;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | @RestController
12 | @RequestMapping("/")
13 | public class Api {
14 |
15 | @Autowired
16 | Service service;
17 |
18 | @GetMapping(produces = MediaType.TEXT_PLAIN_VALUE)
19 | public String get() {
20 | Meter.runMetrics();
21 | return service.doIt();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/springboot-rest/src/main/java/org/objectstyle/springboot/Config.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.springboot;
2 |
3 | import org.objectstyle.di.service.Service;
4 | import org.objectstyle.di.service.ServiceImpl;
5 | import org.objectstyle.di.service.SubService;
6 | import org.objectstyle.di.service.SubServiceImpl;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | @Configuration
11 | public class Config {
12 |
13 | @Bean
14 | public Service service(SubService subService) {
15 | return new ServiceImpl(subService);
16 | }
17 |
18 | @Bean
19 | public SubService subService() {
20 | return new SubServiceImpl();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/springboot-rest/src/main/java/org/objectstyle/springboot/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import java.lang.management.ManagementFactory;
7 | import java.time.LocalDateTime;
8 |
9 | @SpringBootApplication
10 | public class Main {
11 |
12 | public static void main(String[] args) {
13 |
14 | // measuring JVM start time
15 | System.out.println(ManagementFactory.getRuntimeMXBean().getUptime());
16 |
17 | // timestamping the app start point
18 | System.out.println(LocalDateTime.now());
19 |
20 | SpringApplication.run(Main.class, args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/springboot/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.objectstyle.di
9 | di-comparison
10 | 1.1-SNAPSHOT
11 |
12 |
13 | springboot
14 | jar
15 |
16 |
17 | org.objectstyle.springboot.Main
18 |
19 |
20 |
21 |
22 | org.objectstyle.di
23 | common
24 | ${project.version}
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter
29 | ${springboot.version}
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-maven-plugin
38 | ${springboot.version}
39 |
40 |
41 |
42 | repackage
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/springboot/src/main/java/org/objectstyle/springboot/Config.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.springboot;
2 |
3 | import org.objectstyle.di.service.Service;
4 | import org.objectstyle.di.service.ServiceImpl;
5 | import org.objectstyle.di.service.SubService;
6 | import org.objectstyle.di.service.SubServiceImpl;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | @Configuration
11 | public class Config {
12 |
13 | @Bean
14 | public Service service(SubService subService) {
15 | return new ServiceImpl(subService);
16 | }
17 |
18 | @Bean
19 | public SubService subService() {
20 | return new SubServiceImpl();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/springboot/src/main/java/org/objectstyle/springboot/Main.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Main {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Main.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot/src/main/java/org/objectstyle/springboot/Runner.java:
--------------------------------------------------------------------------------
1 | package org.objectstyle.springboot;
2 |
3 | import org.objectstyle.di.service.Service;
4 | import org.springframework.boot.CommandLineRunner;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Component
8 | public class Runner implements CommandLineRunner {
9 |
10 | private Service service;
11 |
12 | public Runner(Service service) {
13 | this.service = service;
14 | }
15 |
16 | @Override
17 | public void run(String... args) throws Exception {
18 | System.out.println(service.doIt());
19 | // Meter.runMetrics();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------