2017-09-17 17:52:41 +02:00
|
|
|
module calendarwebapp.configuration;
|
|
|
|
|
2017-11-09 02:24:15 +01:00
|
|
|
import calendarwebapp.authenticator : Authenticator, MongoDBAuthenticator,
|
|
|
|
MySQLAuthenticator;
|
2017-09-17 17:52:41 +02:00
|
|
|
import calendarwebapp.calendarwebapp : CalendarWebapp;
|
2017-10-30 02:31:48 +01:00
|
|
|
import calendarwebapp.event : EventStore, MongoDBEventStore, MySQLEventStore;
|
2017-11-10 18:20:55 +01:00
|
|
|
import calendarwebapp.passhash : PasswordHasher, SHA256PasswordHasher;
|
2017-09-17 17:52:41 +02:00
|
|
|
|
2017-10-30 02:31:48 +01:00
|
|
|
import mysql : MySQLPool;
|
2017-09-17 17:52:41 +02:00
|
|
|
|
|
|
|
import poodinis;
|
|
|
|
|
|
|
|
import vibe.db.mongo.client : MongoClient;
|
|
|
|
import vibe.db.mongo.collection : MongoCollection;
|
|
|
|
import vibe.db.mongo.mongo : connectMongoDB;
|
|
|
|
|
|
|
|
class Context : ApplicationContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
override void registerDependencies(shared(DependencyContainer) container)
|
|
|
|
{
|
|
|
|
auto mongoClient = connectMongoDB("localhost");
|
2017-11-20 21:51:38 +01:00
|
|
|
auto pool = new MySQLPool("localhost", "root", "Ilemm3Kzj", "CalendarWebapp");
|
2017-10-30 02:31:48 +01:00
|
|
|
container.register!MySQLPool.existingInstance(pool);
|
2017-09-17 17:52:41 +02:00
|
|
|
container.register!MongoClient.existingInstance(mongoClient);
|
2017-10-30 02:31:48 +01:00
|
|
|
container.register!(EventStore, MySQLEventStore);
|
|
|
|
container.register!(Authenticator, MySQLAuthenticator);
|
2017-11-10 18:20:55 +01:00
|
|
|
container.register!(PasswordHasher, SHA256PasswordHasher);
|
2017-09-17 17:52:41 +02:00
|
|
|
container.register!CalendarWebapp;
|
|
|
|
container.register!(ValueInjector!string, StringInjector);
|
|
|
|
container.register!(ValueInjector!MongoCollection, MongoCollectionInjector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class StringInjector : ValueInjector!string
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
string[string] config;
|
|
|
|
|
|
|
|
public:
|
|
|
|
this() const @safe pure nothrow
|
|
|
|
{
|
|
|
|
// dfmt off
|
|
|
|
config = ["Database name" : "CalendarWebapp",
|
|
|
|
"Users collection name": "users",
|
|
|
|
"Events collection name" : "events"];
|
|
|
|
// dfmt on
|
|
|
|
}
|
|
|
|
|
|
|
|
override string get(string key) const @safe pure nothrow
|
|
|
|
{
|
|
|
|
return config[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MongoCollectionInjector : ValueInjector!MongoCollection
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
@Autowire MongoClient mongoClient;
|
|
|
|
@Value("Database name")
|
|
|
|
string databaseName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
override MongoCollection get(string key) @safe
|
|
|
|
{
|
|
|
|
return mongoClient.getCollection(databaseName ~ "." ~ key);
|
|
|
|
}
|
|
|
|
}
|