poodinis/README.md

115 lines
4.5 KiB
Markdown
Raw Normal View History

2023-03-07 00:43:03 +01:00
# Poodinis Dependency Injection Framework
2022-10-27 01:30:15 +02:00
Version 8.1.3
2023-01-11 00:01:51 +01:00
Copyright 2014-2023 Mike Bierlee
2016-02-09 23:18:12 +01:00
Licensed under the terms of the MIT license - See [LICENSE.txt](LICENSE.txt)
2021-06-09 22:22:26 +02:00
[![DUB Package](https://img.shields.io/dub/v/poodinis.svg)](https://code.dlang.org/packages/poodinis) [![CI](https://github.com/mbierlee/poodinis/actions/workflows/dub.yml/badge.svg)](https://github.com/mbierlee/poodinis/actions/workflows/dub.yml)
2016-02-09 23:18:12 +01:00
Poodinis is a dependency injection framework for the D programming language. It is inspired by the [Spring Framework] and [Hypodermic] IoC container for C++. Poodinis supports registering and resolving classes either by concrete type or interface. Automatic injection of dependencies is supported through the use of UDAs or constructors.
2016-02-09 23:18:12 +01:00
Requires at least a D 2.068.2 compatible compiler
2016-02-09 23:18:12 +01:00
Uses the Phobos standard library
Can be built with DUB 1.1.1 or higher
2016-02-09 23:18:12 +01:00
2023-03-07 00:43:03 +01:00
## Features
- Member injection: Injection of dependencies in class members of any visibility (public, private, etc.)
- Constructor injection: Automatic injection of dependencies in class constructors on creation.
- Value injection: Value-types such as primitives or structs can be injected using custom value injectors.
- Type qualifiers: Inject concrete types into members defined only by abstract types.
- Application contexts: Control the creation of dependencies manually through factory methods.
- Multi-threadable: Dependency containers return the same dependencies across all threads.
- Minimal set-up: Creation and injection of conventional classes requires almost no manual dependency configuration.
- Well-tested: Developed test-driven, a great number of scenarios are tested as part of the test suite.
2016-09-03 18:41:58 +02:00
2016-09-03 18:14:46 +02:00
See the [TUTORIAL.md](TUTORIAL.md) and [examples](example) for a complete walkthrough of all features.
2016-02-09 23:18:12 +01:00
2023-03-07 00:43:03 +01:00
## Getting started
2017-07-29 16:36:50 +02:00
### DUB Dependency
2023-03-07 00:43:03 +01:00
2016-02-09 23:18:12 +01:00
See the Poodinis [DUB project page] for instructions on how to include Poodinis into your project.
2017-07-29 16:36:50 +02:00
### Quickstart
2023-03-07 00:43:03 +01:00
2016-02-09 23:18:12 +01:00
The following example shows the typical usage of Poodinis:
2023-03-07 00:43:03 +01:00
2016-02-09 23:18:12 +01:00
```d
import poodinis;
class Driver {}
interface Database {}
class RelationalDatabase : Database {
private Driver driver;
this(Driver driver) { // Automatically injected on creation by container
this.driver = driver;
}
}
2016-02-09 23:18:12 +01:00
class DataWriter {
@Inject
2016-02-09 23:18:12 +01:00
private Database database; // Automatically injected when class is resolved
}
void main() {
auto dependencies = new shared DependencyContainer();
dependencies.register!Driver;
2016-02-09 23:18:12 +01:00
dependencies.register!DataWriter;
dependencies.register!(Database, RelationalDatabase);
auto writer = dependencies.resolve!DataWriter;
}
```
2023-03-07 00:43:03 +01:00
2016-09-03 18:36:26 +02:00
Dependency set-up can further be reduced by enabling "Register on resolve". For more details and examples, see the [examples](example) directory.
2016-02-09 23:18:12 +01:00
2023-03-07 00:43:03 +01:00
## Documentation
2023-02-20 19:34:34 +01:00
You can find the public API documentation [here](https://poodinis.dpldocs.info/v8.1.3/index.html).
2016-12-23 01:32:38 +01:00
Alternatively you can generate documentation from the source code using DUB:
2023-03-07 00:43:03 +01:00
2016-02-09 23:18:12 +01:00
```
dub build --build=ddox
```
2023-03-07 00:43:03 +01:00
2016-02-09 23:18:12 +01:00
The documentation can then be found in docs/
2023-03-07 00:43:03 +01:00
## History
2016-09-03 18:14:46 +02:00
For a full overview of changes, see [CHANGES.md](CHANGES.md)
2023-03-07 00:43:03 +01:00
## Value Injectors
2016-12-26 18:17:26 +01:00
Poodinis doesn't come with implementations of value injectors. Value injectors are available in separate projects:
2023-03-07 00:43:03 +01:00
- [Mirage Config value injector](https://github.com/mbierlee/mirage-injector)
- [Proper-d value injector](https://github.com/mbierlee/poodinis-proper-d-injector)
2016-12-26 18:17:26 +01:00
Have you made any or do you know of any? Please add them to this section via a pull request or open an issue.
2016-12-10 22:26:30 +01:00
2023-03-07 00:43:03 +01:00
## Projects Using Poodinis
- [Hunt Framework](https://github.com/huntlabs/hunt-framework): A Web framework for D Programming Language. Full-stack high-performance.
- [Eloquent](https://github.com/SingingBush/eloquent): A lightweight web application written in D
- [ioc](https://github.com/FilipMalczak/ioc): Slow approach to Inversion of Control in D2 language
## Future Work
- Component scan (auto-registration)
- Phobos collections autowiring
- Named qualifiers
2016-12-23 01:40:00 +01:00
2023-03-07 00:43:03 +01:00
## Contributing
2016-02-09 23:18:12 +01:00
Any and all pull requests are welcome! If you (only) want discuss changes before making them, feel free to open an Issue on github.
Please develop your changes on (a branch based on) the develop branch. Continuous integration is preferred so feature branches are not neccessary.
2023-03-07 00:43:03 +01:00
[spring framework]: http://projects.spring.io/spring-framework/
[hypodermic]: https://github.com/ybainier/hypodermic/
[dub project page]: http://code.dlang.org/packages/poodinis