mirage-injector/README.md

55 lines
1.7 KiB
Markdown
Raw Normal View History

2022-10-31 19:46:04 +01:00
# Mirage Config injector for Poodinis
2023-03-13 21:32:30 +01:00
Version 2.0.0
2023-01-11 00:08:32 +01:00
Copyright 2022-2023 Mike Bierlee
2022-10-31 19:46:04 +01:00
Licensed under the terms of the MIT license - See [LICENSE.txt](LICENSE.txt)
2023-03-13 21:36:12 +01:00
[![DUB Package](https://img.shields.io/dub/v/mirage-injector.svg)](https://code.dlang.org/packages/mirage-injector) [![CI](https://github.com/mbierlee/mirage-injector/actions/workflows/dub.yml/badge.svg)](https://github.com/mbierlee/mirage-injector/actions/workflows/dub.yml)
2023-01-11 00:15:16 +01:00
2022-11-27 16:47:33 +01:00
A config value injector for the [Poodinis dependency injection framework](https://github.com/mbierlee/poodinis) using [Mirage Config](https://github.com/mbierlee/mirage-config)
Requires at least a D 2.097.2 compatible compiler
2022-11-27 16:47:33 +01:00
## Getting started
### DUB Dependency
2023-01-11 00:13:38 +01:00
See the [DUB project page](https://code.dlang.org/packages/mirage-injector) for instructions on how to include Mirage Config into your project.
2022-11-27 16:47:33 +01:00
### Quickstart
```d
import poodinis : DependencyContainer, Value;
import poodinis.valueinjector.mirage : loadConfig;
import std.stdio : writeln;
import std.conv : to;
2023-03-07 00:27:21 +01:00
class Server {
2022-11-27 16:47:33 +01:00
@Value("server.host")
private string host;
@Value("server.port")
private int port;
2023-03-07 00:27:21 +01:00
public void run() {
2022-11-27 16:47:33 +01:00
writeln("Running server on " ~ host ~ ":" ~ port.to!string);
}
}
2023-03-07 00:27:21 +01:00
void main() {
2022-11-27 16:47:33 +01:00
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)