oceandrift-di 0.26.1
Lightweight Dependency Injection (DI) framework
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
oceandrift/di
A lightweight Dependency Injection (DI) framework with focus on simplicity.
- Inversion of Control (IoC).
- Convention over configuration.
- Injects dependencies via constructor parameters.
- Supports structs as well (… as classes and interfaces).
- No clutter – this library is a single, readily comprehensible file.
- No external dependencies. (*Only the D standard library is used.)
Installation
When using DUB, it’s as simple as running dub add oceandrift-di
.
Usage
See in-code documentation for details. Or check out the pre-rendered copy on dpldocs.
class Dependency {}
class Foo {
this(Dependency d) {
// …
}
}
// Bootstrap the DI framework.
// Then let it resolve the whole dependency tree of `Foo`
// and construct dependencies as needed.
auto di = new DI();
Foo foo = di.resolve!Foo();
Less boilerplate
class Foo {
// Mark fields as @dependency.
private @dependency Dependency1 d1;
private @dependency Dependency2 d2;
// Generate a constructor that assigns all dependencies.
mixin DIConstructor;
// The generated constructor corresponds roughly to this code:
/*
public this(
Dependency1 d1,
Dependency2 d2,
) {
this.d1 = d1;
this.d2 = d2;
}
*/
}
- Registered by Elias Batek
- 0.26.1 released 11 months ago
- oceandrift/di
- BSL-1.0
- Copyright © 2024 Elias Batek
- Dependencies:
- none
- Versions:
-
0.26.1 2024-Jan-27 0.26.0 2024-Jan-27 0.25.2 2024-Jan-14 0.25.1 2024-Jan-14 0.25.0 2024-Jan-14 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
3 downloads total
-
- Score:
- 0.7
- Short URL:
- oceandrift-di.dub.pm