Skip to content

Commit

Permalink
Cayenne impl
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Mar 31, 2018
1 parent 06788f6 commit 0543e7d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Guice vs Dagger Comparison
# DI Containers Comparision

Comparing a simple app written on top of Cayenne DI, Dagger 2, and
Guice.

## Idea Setup

Expand Down
43 changes: 43 additions & 0 deletions cayennedi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.objectstyle.dagger</groupId>
<artifactId>dagger-sandbox</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>cayennedi</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>jar</packaging>

<properties>
<main.class>org.objectstyle.cayenne.Main</main.class>
</properties>

<dependencies>
<dependency>
<groupId>org.objectstyle.dagger</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cayenne</groupId>
<artifactId>cayenne-di</artifactId>
<version>${cayenne.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
12 changes: 12 additions & 0 deletions cayennedi/src/main/java/org/objectstyle/cayenne/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.objectstyle.cayenne;

import org.apache.cayenne.di.DIBootstrap;
import org.objectstyle.dagger.service.Service;

public class Main {

public static void main(String[] args) {
Service s = DIBootstrap.createInjector(new MainModule()).getInstance(Service.class);
System.out.println(s.doIt());
}
}
16 changes: 16 additions & 0 deletions cayennedi/src/main/java/org/objectstyle/cayenne/MainModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.objectstyle.cayenne;

import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.Module;
import org.objectstyle.dagger.service.Service;
import org.objectstyle.dagger.service.SubService;
import org.objectstyle.dagger.service.SubServiceImpl;

public class MainModule implements Module {

@Override
public void configure(Binder binder) {
binder.bind(Service.class).toProvider(SubServiceProvider.class);
binder.bind(SubService.class).to(SubServiceImpl.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.objectstyle.cayenne;

import org.apache.cayenne.di.DIRuntimeException;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.di.Provider;
import org.objectstyle.dagger.service.Service;
import org.objectstyle.dagger.service.ServiceImpl;
import org.objectstyle.dagger.service.SubService;

public class SubServiceProvider implements Provider<Service> {

@Inject
private SubService subService;

@Override
public Service get() throws DIRuntimeException {
return new ServiceImpl(subService);
}
}
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

<dagger.version>2.15</dagger.version>
<guice.version>4.2.0</guice.version>
<cayenne.version>4.0.B2</cayenne.version>

</properties>

<modules>
<module>common</module>
<module>dagger</module>
<module>guice</module>
<module>cayennedi</module>
</modules>

<build>
Expand Down

0 comments on commit 0543e7d

Please sign in to comment.