diff --git a/source/poodinis/container.d b/source/poodinis/container.d index d7e2a7a..784d87b 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -74,7 +74,7 @@ public enum ResolveOption { /** * Does not throw a resolve exception when a type is not registered but will - * return null instead. + * return null instead. If the type is an array, an empty array is returned instead. */ noResolveException } @@ -348,12 +348,16 @@ synchronized class DependencyContainer { * Animal[] animals = container.resolveAll!Animal; * --- */ - public RegistrationType[] resolveAll(RegistrationType)() { + public RegistrationType[] resolveAll(RegistrationType)(ResolveOption[] resolveOptions = []) { RegistrationType[] instances; TypeInfo resolveType = typeid(RegistrationType); auto qualifiedRegistrations = resolveType in registrations; if (!qualifiedRegistrations) { + if (hasOption(resolveOptions, persistentResolveOptions, ResolveOption.noResolveException)) { + return []; + } + throw new ResolveException("Type not registered.", resolveType); } diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index 3899a5a..b2d9b0f 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -662,4 +662,11 @@ version(unittest) { auto instance = container.resolve!TestInterface([ResolveOption.noResolveException]); assert(instance is null); } + + // ResolveOption noResolveException does not throw for resolveAll + unittest { + shared(DependencyContainer) container = new DependencyContainer(); + auto instances = container.resolveAll!TestInterface([ResolveOption.noResolveException]); + assert(instances.length == 0); + } }