diff --git a/.gitignore b/.gitignore index 3931941..04d2afe 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ poodinis-mirage-config-injector-test-* *.o *.obj *.lst -*.pdb \ No newline at end of file +*.pdb +/bin/ \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..59e5e08 --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,4 @@ +# Mirage Config injector for Poodinis Changelog + +**Version 1.0.0** (27-11-2022) +* Initial version \ No newline at end of file diff --git a/README.md b/README.md index 0f0f29d..fbfda52 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,50 @@ Version 0.0.0 Copyright 2022 Mike Bierlee Licensed under the terms of the MIT license - See [LICENSE.txt](LICENSE.txt) -A config value injector for the [Poodinis dependency injection framework](https://github.com/mbierlee/poodinis) using [Mirage Config](https://github.com/mbierlee/mirage-config) \ No newline at end of file +A config value injector for the [Poodinis dependency injection framework](https://github.com/mbierlee/poodinis) using [Mirage Config](https://github.com/mbierlee/mirage-config) + +## Getting started + +### DUB Dependency + +See the [DUB project page](https://code.dlang.org/packages/poodinis-mirage-config-injector) for instructions on how to include Mirage Config into your project. + +### Quickstart + +```d +import poodinis : DependencyContainer, Value; +import poodinis.valueinjector.mirage : loadConfig; + +import std.stdio : writeln; +import std.conv : to; + +class Server +{ + @Value("server.host") + private string host; + + @Value("server.port") + private int port; + + public void run() + { + writeln("Running server on " ~ host ~ ":" ~ port.to!string); + } +} + +void main() +{ + auto container = new shared DependencyContainer(); + container.register!Server; + container.loadConfig("config.ini"); + + auto server = container.resolve!Server; + server.run(); +} +``` + +Functions such as `loadConfig` are the same as available in Mirage. All individual loaders and parses are available. For more information on how to use Mirage, see https://github.com/mbierlee/mirage-config/blob/main/README.md + +## History + +For a full overview of changes, see [CHANGES.md](CHANGES.md) diff --git a/dub.json b/dub.json index eda0fc6..f4f102b 100644 --- a/dub.json +++ b/dub.json @@ -8,5 +8,27 @@ "dependencies": { "poodinis": "~>8.1.3", "mirage-config": "~>1.0.0" - } + }, + "configurations": [ + { + "name": "library", + "targetType": "library" + }, + { + "name": "unittest", + "targetType": "executable", + "sourcePaths": ["source"], + "mainSourceFile": "testmain.d" + }, + { + "name": "quickstartExample", + "targetType": "executable", + "targetName": "quickstartExample", + "sourcePaths": ["examples/quickstart"], + "importPaths": ["source"], + "copyFiles": ["examples/quickstart/config.ini"], + "targetPath": "bin/examples/quickstart", + "workingDirectory": "bin/examples/quickstart" + } + ] } diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..3e25ee7 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,10 @@ +To run any of these examples, specify the relevant DUB configuration: +``` +dub run --build=release --config=Example +``` +Where \ corresponds to the name of the folder where the code example is in (camel-cased). + +e.g: +``` +dub run --build=release --config=quickstartExample +``` diff --git a/examples/quickstart/app.d b/examples/quickstart/app.d new file mode 100644 index 0000000..9342716 --- /dev/null +++ b/examples/quickstart/app.d @@ -0,0 +1,38 @@ +/** + * Mirage Config value injector for the Poodinis Dependency Injection Framework + * Copyright 2022 Mike Bierlee + * This software is licensed under the terms of the MIT license. + * The full terms of the license can be found in the LICENSE file. + */ + +module examples.quickstart.app; + +import poodinis : DependencyContainer, Value; +import poodinis.valueinjector.mirage : loadConfig; + +import std.stdio : writeln; +import std.conv : to; + +class Server +{ + @Value("server.host") + private string host; + + @Value("server.port") + private int port; + + public void run() + { + writeln("Running server on " ~ host ~ ":" ~ port.to!string); + } +} + +void main() +{ + auto container = new shared DependencyContainer(); + container.register!Server; + container.loadConfig("config.ini"); + + auto server = container.resolve!Server; + server.run(); +} diff --git a/examples/quickstart/config.ini b/examples/quickstart/config.ini new file mode 100644 index 0000000..4da6903 --- /dev/null +++ b/examples/quickstart/config.ini @@ -0,0 +1,3 @@ +[server] +host = "0.0.0.0" +port = 8080 \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..da3048c --- /dev/null +++ b/makefile @@ -0,0 +1,18 @@ +.PHONY: build +.PHONY: test +.PHONY: clean + +build: + dub build --build=release + +build-docs: + dub build --build=ddox + +test: + dub test + +clean: + dub clean + +run-quickstartExample: + dub run --build=release --config=quickstartExample \ No newline at end of file diff --git a/source/poodinis/valueinjector/mirage.d b/source/poodinis/valueinjector/mirage.d index 50854f7..d5c9c31 100644 --- a/source/poodinis/valueinjector/mirage.d +++ b/source/poodinis/valueinjector/mirage.d @@ -1,5 +1,5 @@ /** - * Poodinis Dependency Injection Framework + * Mirage Config value injector for the Poodinis Dependency Injection Framework * Copyright 2022 Mike Bierlee * This software is licensed under the terms of the MIT license. * The full terms of the license can be found in the LICENSE file. diff --git a/testmain.d b/testmain.d new file mode 100644 index 0000000..db75d6c --- /dev/null +++ b/testmain.d @@ -0,0 +1,15 @@ +/** + * Authors: + * Mike Bierlee, m.bierlee@lostmoment.com + * Copyright: 2022 Mike Bierlee + * License: + * This software is licensed under the terms of the MIT license. + * The full terms of the license can be found in the LICENSE file. + */ + +module testmain; + +version (unittest) { + void main() { + } +}