2016-02-09 23:18:12 +01:00
Poodinis Dependency Injection Framework
=======================================
2016-08-08 21:32:27 +02:00
Version 7.0.0
2016-02-09 23:18:12 +01:00
Copyright 2014-2016 Mike Bierlee
Licensed under the terms of the MIT license - See [LICENSE.txt ](LICENSE.txt )
Master: [![Build Status ](https://api.travis-ci.org/mbierlee/poodinis.png?branch=master )](https://travis-ci.org/mbierlee/poodinis) - Dev: [![Build Status ](https://api.travis-ci.org/mbierlee/poodinis.png?branch=develop )](https://travis-ci.org/mbierlee/poodinis)
2016-08-23 21:10:31 +02: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.0 compatible compiler
Uses the Phobos standard library
2016-06-27 21:01:19 +02:00
Can be built with DUB 0.9.24 or higher
2016-02-09 23:18:12 +01:00
2016-09-03 18:14:46 +02: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.
* 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.
2016-09-03 18:36:26 +02:00
* Well-tested: Developed test-driven, a great number of scenarios are tested as part of the test suite.
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
Getting started
---------------
###DUB Dependency
See the Poodinis [DUB project page] for instructions on how to include Poodinis into your project.
###Quickstart
The following example shows the typical usage of Poodinis:
```d
import poodinis;
2016-09-03 18:19:38 +02:00
class Driver {}
2016-09-03 18:36:26 +02:00
interface Database {};
2016-09-03 18:19:38 +02:00
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 {
@Autowire
private Database database; // Automatically injected when class is resolved
}
void main() {
2016-08-08 22:17:17 +02:00
auto dependencies = new shared DependencyContainer();
2016-09-03 18:19:38 +02:00
dependencies.register!Driver;
2016-02-09 23:18:12 +01:00
dependencies.register!DataWriter;
dependencies.register!(Database, RelationalDatabase);
auto writer = dependencies.resolve!DataWriter;
}
```
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
Documentation
-------------
You can generate Public API documentation from the source code using DUB:
```
dub build --build=ddox
```
The documentation can then be found in docs/
2016-09-03 18:14:46 +02:00
History
-------
For a full overview of changes, see [CHANGES.md ](CHANGES.md )
2016-02-09 23:18:12 +01:00
Future Work
-----------
* Component scan (auto-registration)
* Phobos collections autowiring
* Named qualifiers
2016-02-11 20:46:16 +01:00
* Value type injection
2016-02-09 23:18:12 +01:00
Contributing
------------
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.
[Spring Framework]: http://projects.spring.io/spring-framework/
[Hypodermic]: https://github.com/ybainier/hypodermic/
[DUB]: http://code.dlang.org/
[DUB project page]: http://code.dlang.org/packages/poodinis
[Github issue tracker]: https://github.com/mbierlee/poodinis/issues