Skip to content

Commit 8847bf4

Browse files
committed
Enabled injection in commands
1 parent 8ad7177 commit 8847bf4

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/main/java/org/javawebstack/framework/WebApplication.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public WebApplication(){
4646
injector.setInstance(Config.class, config);
4747
injector.setInstanceUnsafe(getClass(), this);
4848
injector.setInstance(WebApplication.class, this);
49+
injector.setInstance(CommandSystem.class, commandSystem);
50+
commandSystem.setInjector(injector);
51+
4952
setupModules();
5053
modules.forEach(m -> m.beforeSetupConfig(this, config));
5154
setupConfig(config);
@@ -78,9 +81,11 @@ public WebApplication(){
7881
ex.printStackTrace();
7982
}
8083
}
84+
8185
modules.forEach(m -> m.beforeSetupInjection(this, injector));
8286
setupInjection(injector);
8387
modules.forEach(m -> m.setupInjection(this, injector));
88+
8489
server = new HTTPServer()
8590
.port(config.getInt("http.server.port", 80));
8691
injector.setInstance(HTTPServer.class, server);
@@ -95,10 +100,11 @@ public WebApplication(){
95100
modules.forEach(m -> m.beforeSetupServer(this, server));
96101
setupServer(server);
97102
modules.forEach(m -> m.setupServer(this, server));
103+
98104
setupCommands(commandSystem);
99105
modules.forEach(m -> m.setupCommands(this, commandSystem));
100-
commandSystem.addCommand("start", new StartCommand(this));
101-
commandSystem.addCommand("sh", new ShellCommand(this));
106+
commandSystem.addCommand("start", new StartCommand());
107+
commandSystem.addCommand("sh", new ShellCommand());
102108
}
103109

104110
public WebApplication addModule(Module module){

src/main/java/org/javawebstack/framework/command/ShellCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
import org.javawebstack.command.CommandResult;
88
import org.javawebstack.command.CommandSystem;
99
import org.javawebstack.framework.WebApplication;
10+
import org.javawebstack.injector.Inject;
1011
import org.javawebstack.orm.ORM;
1112

1213
import java.io.InputStreamReader;
1314
import java.util.List;
1415
import java.util.Map;
1516

1617
public class ShellCommand implements Command {
17-
private final WebApplication application;
18-
public ShellCommand(WebApplication application){
19-
this.application = application;
20-
}
18+
@Inject
19+
private WebApplication application;
2120
public CommandResult execute(CommandSystem system, List<String> list, Map<String, List<String>> map) {
2221
InputStreamReader reader = new InputStreamReader(System.in);
2322
Interpreter interpreter = new Interpreter();

src/main/java/org/javawebstack/framework/command/StartCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import org.javawebstack.command.CommandResult;
55
import org.javawebstack.command.CommandSystem;
66
import org.javawebstack.framework.WebApplication;
7+
import org.javawebstack.injector.Inject;
78

89
import java.util.List;
910
import java.util.Map;
1011

1112
public class StartCommand implements Command {
12-
private final WebApplication application;
13-
public StartCommand(WebApplication application){
14-
this.application = application;
15-
}
13+
@Inject
14+
private WebApplication application;
1615
public CommandResult execute(CommandSystem commandSystem, List<String> list, Map<String, List<String>> map) {
1716
try {
1817
application.start();

0 commit comments

Comments
 (0)