diff --git a/CHANGES.md b/CHANGES.md index ca30aa6..580fae3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index 3c4aad9..a8e6550 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -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; diff --git a/source/poodinis/inject.d b/source/poodinis/inject.d new file mode 100644 index 0000000..8f4c82c --- /dev/null +++ b/source/poodinis/inject.d @@ -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; diff --git a/source/poodinis/package.d b/source/poodinis/package.d index 40e5856..0b33f7a 100644 --- a/source/poodinis/package.d +++ b/source/poodinis/package.d @@ -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; diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index 0d9e56d..9e82749 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -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); + } } diff --git a/test/poodinis/testclasses.d b/test/poodinis/testclasses.d index 4790c9c..c233d4f 100644 --- a/test/poodinis/testclasses.d +++ b/test/poodinis/testclasses.d @@ -650,4 +650,8 @@ version (unittest) { return valla; } } + + class WithInjectAttribute { + public @Inject ComponentA componentA; + } }