-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from UTSCCSCC01/feature/DependencyInjection
Feature/dependency injection
- Loading branch information
Showing
8 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
package ca.utoronto.utm.mcs; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import org.neo4j.driver.*; | ||
|
||
|
||
@Module | ||
public class ReqHandlerModule { | ||
// TODO Complete This Module | ||
private final String uriDb = "bolt://localhost:7687"; | ||
private final String username = "neo4j"; | ||
private final String password = "123456"; | ||
|
||
@Provides | ||
public Neo4jDAO provideNeo4jDAO(Driver driver) { | ||
|
||
return new Neo4jDAO(driver); | ||
} | ||
|
||
@Provides | ||
public Driver provideDriver(){ | ||
return GraphDatabase.driver(this.uriDb, AuthTokens.basic(this.username, this.password)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
package ca.utoronto.utm.mcs; | ||
|
||
import com.sun.net.httpserver.HttpServer; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class Server { | ||
// TODO Complete This Class | ||
private HttpServer httpServer; | ||
@Inject | ||
public Server(HttpServer httpServer){ | ||
this.httpServer = httpServer; | ||
} | ||
public void createContext(String path, ReqHandler reqHandler){ | ||
this.httpServer.createContext(path, reqHandler); | ||
} | ||
public void startServer(){ | ||
this.httpServer.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,33 @@ | ||
package ca.utoronto.utm.mcs; | ||
|
||
import com.sun.net.httpserver.HttpServer; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
|
||
@Module | ||
public class ServerModule { | ||
// TODO Complete This Module | ||
@Provides | ||
public InetSocketAddress provideInetSocketAddress(){ | ||
return new InetSocketAddress("0.0.0.0", 8080); | ||
} | ||
@Provides | ||
public HttpServer provideHttpServer(InetSocketAddress inetSocketAddress) { | ||
try { | ||
HttpServer server = HttpServer.create(inetSocketAddress, 0); | ||
|
||
return server; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
@Provides | ||
public Server provideServer(HttpServer httpServer){ | ||
return new Server(httpServer); | ||
} | ||
} |