Skip to content

Commit c3dc573

Browse files
committed
Adding dependency injection
Defining a Dagger Module
1 parent 168bbbc commit c3dc573

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>eu.jangos</groupId>
55
<artifactId>JaNGOSExtractor</artifactId>
6-
<version>1.0</version>
6+
<version>1.1</version>
77
<packaging>jar</packaging>
88
<properties>
99
<java.version>11</java.version>
@@ -19,6 +19,13 @@
1919
<groupId>org.apache.maven.plugins</groupId>
2020
<artifactId>maven-compiler-plugin</artifactId>
2121
<version>3.8.0</version>
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.google.dagger</groupId>
25+
<artifactId>dagger-compiler</artifactId>
26+
<version>2.21</version>
27+
</dependency>
28+
</dependencies>
2229
</plugin>
2330
<plugin>
2431
<groupId>org.apache.maven.plugins</groupId>
@@ -92,6 +99,11 @@
9299
<version>5.4.1</version>
93100
<scope>test</scope>
94101
</dependency>
102+
<dependency>
103+
<groupId>com.google.dagger</groupId>
104+
<artifactId>dagger</artifactId>
105+
<version>2.21</version>
106+
</dependency>
95107
</dependencies>
96108

97109
<name>JaNGOSExtractor</name>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2019 Warkdev
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package eu.jangos.extractor.di;
18+
19+
import dagger.Module;
20+
import dagger.Provides;
21+
import eu.jangos.extractor.file.mpq.MPQManager;
22+
import javax.inject.Singleton;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
/**
27+
*
28+
* @author Warkdev
29+
*/
30+
@Module
31+
public class ExtractorModule {
32+
33+
private static final Logger logger = LoggerFactory.getLogger(ExtractorModule.class);
34+
35+
private final String directory;
36+
37+
public ExtractorModule(String directory) {
38+
this.directory = directory;
39+
}
40+
41+
@Provides
42+
@Singleton
43+
public MPQManager provideMPQManager() {
44+
try {
45+
return new MPQManager(this.directory);
46+
} catch (Exception e) {
47+
logger.error("Error while generating MPQManager");
48+
}
49+
50+
return null;
51+
}
52+
53+
}

src/main/java/module-info.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
requires static javafx.controls;
2626
requires static systems.crigges.jmpq;
2727
requires static javafx.swing;
28-
28+
requires static dagger;
29+
requires static javax.inject;
30+
2931
exports eu.jangos.extractor.file;
3032
exports eu.jangos.extractor.file.exception;
3133
exports eu.jangos.extractor.file.impl;

0 commit comments

Comments
 (0)