mirror of
https://github.com/mbierlee/mirage-injector.git
synced 2024-11-14 21:04:00 +01:00
Reformat code to use otbs bracestyle
This commit is contained in:
parent
40b0c9522d
commit
ae31190ea5
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"dfmt.braceStyle": "allman"
|
"dfmt.braceStyle": "otbs"
|
||||||
}
|
}
|
|
@ -23,22 +23,19 @@ import poodinis.valueinjector.mirage : loadConfig;
|
||||||
import std.stdio : writeln;
|
import std.stdio : writeln;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
|
|
||||||
class Server
|
class Server {
|
||||||
{
|
|
||||||
@Value("server.host")
|
@Value("server.host")
|
||||||
private string host;
|
private string host;
|
||||||
|
|
||||||
@Value("server.port")
|
@Value("server.port")
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
writeln("Running server on " ~ host ~ ":" ~ port.to!string);
|
writeln("Running server on " ~ host ~ ":" ~ port.to!string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main() {
|
||||||
{
|
|
||||||
auto container = new shared DependencyContainer();
|
auto container = new shared DependencyContainer();
|
||||||
container.register!Server;
|
container.register!Server;
|
||||||
container.loadConfig("config.ini");
|
container.loadConfig("config.ini");
|
||||||
|
|
|
@ -15,22 +15,19 @@ import poodinis.valueinjector.mirage : loadConfig;
|
||||||
import std.stdio : writeln;
|
import std.stdio : writeln;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
|
|
||||||
class Server
|
class Server {
|
||||||
{
|
|
||||||
@Value("server.host")
|
@Value("server.host")
|
||||||
private string host;
|
private string host;
|
||||||
|
|
||||||
@Value("server.port")
|
@Value("server.port")
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
writeln("Running server on " ~ host ~ ":" ~ port.to!string);
|
writeln("Running server on " ~ host ~ ":" ~ port.to!string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main() {
|
||||||
{
|
|
||||||
auto container = new shared DependencyContainer();
|
auto container = new shared DependencyContainer();
|
||||||
container.register!Server;
|
container.register!Server;
|
||||||
container.loadConfig("config.ini");
|
container.loadConfig("config.ini");
|
||||||
|
|
|
@ -18,13 +18,11 @@ import mirage.json : mirageLoadJsonConfig = loadJsonConfig, mirageParseJsonConfi
|
||||||
import mirage.java : mirageLoadJavaConfig = loadJavaConfig, mirageParseJavaConfig = parseJavaConfig;
|
import mirage.java : mirageLoadJavaConfig = loadJavaConfig, mirageParseJavaConfig = parseJavaConfig;
|
||||||
import mirage.ini : mirageLoadIniConfig = loadIniConfig, mirageParseIniConfig = parseIniConfig;
|
import mirage.ini : mirageLoadIniConfig = loadIniConfig, mirageParseIniConfig = parseIniConfig;
|
||||||
|
|
||||||
class MirageValueInjector(Type) : ValueInjector!Type
|
class MirageValueInjector(Type) : ValueInjector!Type {
|
||||||
{
|
|
||||||
@Autowire
|
@Autowire
|
||||||
private ConfigDictionary config;
|
private ConfigDictionary config;
|
||||||
|
|
||||||
public Type get(string key)
|
public Type get(string key) {
|
||||||
{
|
|
||||||
return config.get!Type(key);
|
return config.get!Type(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +49,7 @@ alias MirageStringValueInjector = MirageValueInjector!string;
|
||||||
* Params:
|
* Params:
|
||||||
* container = Dependency container to register injectors with.
|
* container = Dependency container to register injectors with.
|
||||||
*/
|
*/
|
||||||
public void registerMirageInjectors(shared(DependencyContainer) container)
|
public void registerMirageInjectors(shared(DependencyContainer) container) {
|
||||||
{
|
|
||||||
container.register!(ValueInjector!bool, MirageBoolValueInjector);
|
container.register!(ValueInjector!bool, MirageBoolValueInjector);
|
||||||
container.register!(ValueInjector!byte, MirageByteValueInjector);
|
container.register!(ValueInjector!byte, MirageByteValueInjector);
|
||||||
container.register!(ValueInjector!ubyte, MirageUbyteValueInjector);
|
container.register!(ValueInjector!ubyte, MirageUbyteValueInjector);
|
||||||
|
@ -82,8 +79,7 @@ public void registerMirageInjectors(shared(DependencyContainer) container)
|
||||||
* configPath = Path to the configuration file.
|
* configPath = Path to the configuration file.
|
||||||
* Throws: ConfigCreationException when the file's extension is unrecognized.
|
* Throws: ConfigCreationException when the file's extension is unrecognized.
|
||||||
*/
|
*/
|
||||||
public void loadConfig(shared(DependencyContainer) container, const string configPath)
|
public void loadConfig(shared(DependencyContainer) container, const string configPath) {
|
||||||
{
|
|
||||||
processConfig(container, configPath, &mirageLoadConfig);
|
processConfig(container, configPath, &mirageLoadConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +91,7 @@ public void loadConfig(shared(DependencyContainer) container, const string confi
|
||||||
* container = Dependency container to register config and injectors with.
|
* container = Dependency container to register config and injectors with.
|
||||||
* configPath = Path to the configuration file.
|
* configPath = Path to the configuration file.
|
||||||
*/
|
*/
|
||||||
public void loadJsonConfig(shared(DependencyContainer) container, const string configPath)
|
public void loadJsonConfig(shared(DependencyContainer) container, const string configPath) {
|
||||||
{
|
|
||||||
processConfig(container, configPath, &mirageLoadJsonConfig);
|
processConfig(container, configPath, &mirageLoadJsonConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +103,7 @@ public void loadJsonConfig(shared(DependencyContainer) container, const string c
|
||||||
* container = Dependency container to register config and injectors with.
|
* container = Dependency container to register config and injectors with.
|
||||||
* configPath = Path to the configuration file.
|
* configPath = Path to the configuration file.
|
||||||
*/
|
*/
|
||||||
public void loadJavaProperties(shared(DependencyContainer) container, const string configPath)
|
public void loadJavaProperties(shared(DependencyContainer) container, const string configPath) {
|
||||||
{
|
|
||||||
processConfig(container, configPath, &mirageLoadJavaConfig);
|
processConfig(container, configPath, &mirageLoadJavaConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,8 +118,7 @@ alias loadJavaConfig = loadJavaProperties;
|
||||||
* container = Dependency container to register config and injectors with.
|
* container = Dependency container to register config and injectors with.
|
||||||
* configPath = Path to the configuration file.
|
* configPath = Path to the configuration file.
|
||||||
*/
|
*/
|
||||||
public void loadIniConfig(shared(DependencyContainer) container, const string configPath)
|
public void loadIniConfig(shared(DependencyContainer) container, const string configPath) {
|
||||||
{
|
|
||||||
processConfig(container, configPath, &mirageLoadIniConfig);
|
processConfig(container, configPath, &mirageLoadIniConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,8 +129,7 @@ public void loadIniConfig(shared(DependencyContainer) container, const string co
|
||||||
* container = Dependency container to register config and injectors with.
|
* container = Dependency container to register config and injectors with.
|
||||||
* config = Contents of the config to parse.
|
* config = Contents of the config to parse.
|
||||||
*/
|
*/
|
||||||
public void parseJsonConfig(shared(DependencyContainer) container, const string config)
|
public void parseJsonConfig(shared(DependencyContainer) container, const string config) {
|
||||||
{
|
|
||||||
processConfig(container, config, &mirageParseJsonConfig);
|
processConfig(container, config, &mirageParseJsonConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,8 +140,7 @@ public void parseJsonConfig(shared(DependencyContainer) container, const string
|
||||||
* container = Dependency container to register config and injectors with.
|
* container = Dependency container to register config and injectors with.
|
||||||
* config = Contents of the properties to parse.
|
* config = Contents of the properties to parse.
|
||||||
*/
|
*/
|
||||||
public void parseJavaProperties(shared(DependencyContainer) container, const string properties)
|
public void parseJavaProperties(shared(DependencyContainer) container, const string properties) {
|
||||||
{
|
|
||||||
processConfig(container, properties, &mirageParseJavaConfig);
|
processConfig(container, properties, &mirageParseJavaConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,8 +154,7 @@ alias parseJavaConfig = parseJavaProperties;
|
||||||
* container = Dependency container to register config and injectors with.
|
* container = Dependency container to register config and injectors with.
|
||||||
* config = Contents of the config to parse.
|
* config = Contents of the config to parse.
|
||||||
*/
|
*/
|
||||||
public void parseIniConfig(shared(DependencyContainer) container, const string config)
|
public void parseIniConfig(shared(DependencyContainer) container, const string config) {
|
||||||
{
|
|
||||||
processConfig(container, config, &mirageParseIniConfig);
|
processConfig(container, config, &mirageParseIniConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,18 +162,15 @@ private void processConfig(
|
||||||
shared(DependencyContainer) container,
|
shared(DependencyContainer) container,
|
||||||
const string configProcParam,
|
const string configProcParam,
|
||||||
ConfigDictionary function(const string configProcParam) procFunc
|
ConfigDictionary function(const string configProcParam) procFunc
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
container.registerMirageInjectors;
|
container.registerMirageInjectors;
|
||||||
auto config = procFunc(configProcParam);
|
auto config = procFunc(configProcParam);
|
||||||
container.register!ConfigDictionary.existingInstance(config);
|
container.register!ConfigDictionary.existingInstance(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
version (unittest)
|
version (unittest) {
|
||||||
{
|
|
||||||
|
|
||||||
class TestClass
|
class TestClass {
|
||||||
{
|
|
||||||
@Value("horse.name")
|
@Value("horse.name")
|
||||||
public string horseName;
|
public string horseName;
|
||||||
|
|
||||||
|
@ -192,15 +179,13 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Register primitive value injectors")
|
@("Register primitive value injectors")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.registerMirageInjectors;
|
dependencies.registerMirageInjectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Load config file using generic loader")
|
@("Load config file using generic loader")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.loadConfig("testfiles/horses.ini");
|
dependencies.loadConfig("testfiles/horses.ini");
|
||||||
|
|
||||||
|
@ -209,8 +194,7 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Inject loaded config into class values")
|
@("Inject loaded config into class values")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.register!TestClass;
|
dependencies.register!TestClass;
|
||||||
dependencies.loadConfig("testfiles/horses.ini");
|
dependencies.loadConfig("testfiles/horses.ini");
|
||||||
|
@ -221,8 +205,7 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Load JSON config")
|
@("Load JSON config")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.register!TestClass;
|
dependencies.register!TestClass;
|
||||||
dependencies.loadJsonConfig("testfiles/horses.json");
|
dependencies.loadJsonConfig("testfiles/horses.json");
|
||||||
|
@ -232,8 +215,7 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Parse JSON config")
|
@("Parse JSON config")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.register!TestClass;
|
dependencies.register!TestClass;
|
||||||
dependencies.parseJsonConfig("
|
dependencies.parseJsonConfig("
|
||||||
|
@ -250,8 +232,7 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Load Java config")
|
@("Load Java config")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.register!TestClass;
|
dependencies.register!TestClass;
|
||||||
dependencies.loadJavaConfig("testfiles/horses.properties");
|
dependencies.loadJavaConfig("testfiles/horses.properties");
|
||||||
|
@ -261,8 +242,7 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Parse Java config")
|
@("Parse Java config")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.register!TestClass;
|
dependencies.register!TestClass;
|
||||||
dependencies.parseJavaConfig("
|
dependencies.parseJavaConfig("
|
||||||
|
@ -275,8 +255,7 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Load INI config")
|
@("Load INI config")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.register!TestClass;
|
dependencies.register!TestClass;
|
||||||
dependencies.loadIniConfig("testfiles/horses.ini");
|
dependencies.loadIniConfig("testfiles/horses.ini");
|
||||||
|
@ -286,8 +265,7 @@ version (unittest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@("Parse INI config")
|
@("Parse INI config")
|
||||||
unittest
|
unittest {
|
||||||
{
|
|
||||||
auto dependencies = new shared DependencyContainer;
|
auto dependencies = new shared DependencyContainer;
|
||||||
dependencies.register!TestClass;
|
dependencies.register!TestClass;
|
||||||
dependencies.parseIniConfig("
|
dependencies.parseIniConfig("
|
||||||
|
|
Loading…
Reference in a new issue