mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add support for JSR330 @Inject attribute
This commit is contained in:
parent
733c2aa236
commit
3fa4e15d6f
|
@ -1,8 +1,9 @@
|
|||
# Poodinis Changelog
|
||||
|
||||
**Version 8.1.4** (??????)
|
||||
**Version 8.2.0** (??????)
|
||||
|
||||
- FIX some dlang deprecation warnings (#43). Some remain due to further issues in dlang/phobos.
|
||||
- ADD support for JSR330 @Inject attribute. It will be the preferred attribute from now on. However, @Autowire is not deprecated and will still work.
|
||||
|
||||
**Version 8.1.3** (27-10-2022)
|
||||
|
||||
|
|
|
@ -69,6 +69,8 @@ private struct UseMemberType {
|
|||
* The members of an instance of "HybridCar" will now be autowired properly, because the autowire mechanism will
|
||||
* autowire member "fuelEngine" as if it's of type "FuelEngine". This means that the members of instance "fuelEngine"
|
||||
* will also be autowired because the autowire mechanism knows that member "fuelEngine" is an instance of "FuelEngine"
|
||||
*
|
||||
* See_Also: Inject
|
||||
*/
|
||||
struct Autowire(QualifierType) {
|
||||
QualifierType qualifier;
|
||||
|
|
21
source/poodinis/inject.d
Normal file
21
source/poodinis/inject.d
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* An analogue to JSR330
|
||||
*
|
||||
* Authors:
|
||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||
* Copyright: 2014-2023 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 poodinis.inject;
|
||||
|
||||
import poodinis.autowire : Autowire;
|
||||
|
||||
/**
|
||||
* UDA for annotating class members as candidates for injection.
|
||||
*
|
||||
* See_Also: Autowire
|
||||
*/
|
||||
alias Inject = Autowire;
|
|
@ -16,5 +16,6 @@ public import poodinis.container;
|
|||
public import poodinis.context;
|
||||
public import poodinis.factory;
|
||||
public import poodinis.imports;
|
||||
public import poodinis.inject;
|
||||
public import poodinis.registration;
|
||||
public import poodinis.valueinjection;
|
||||
|
|
|
@ -648,4 +648,14 @@ version (unittest) {
|
|||
assert(instance.lala == 42);
|
||||
assert(instance.lala(77) == 77);
|
||||
}
|
||||
|
||||
// Test autowiring using @Inject attribute
|
||||
unittest {
|
||||
auto container = new shared DependencyContainer();
|
||||
container.register!ComponentA;
|
||||
container.register!WithInjectAttribute;
|
||||
|
||||
auto instance = container.resolve!WithInjectAttribute;
|
||||
assert(instance.componentA is container.resolve!ComponentA);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -650,4 +650,8 @@ version (unittest) {
|
|||
return valla;
|
||||
}
|
||||
}
|
||||
|
||||
class WithInjectAttribute {
|
||||
public @Inject ComponentA componentA;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue