From f7578d79a3a96883a35efb6daa63d2ce18b06c00 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Thu, 27 Oct 2022 01:42:09 +0300 Subject: [PATCH] Fix unnecessary re-registration of types when registerBeforeResolving is specified --- CHANGES.md | 4 ++++ source/poodinis/container.d | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 42359f6..7e74e5f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ Poodinis Changelog ================== + +**Version NEXT** +* FIX unnecessary re-registration of types when registerBeforeResolving is specified. + **Version 8.1.2** * FIX compilation error on importing template types that are not actually types. diff --git a/source/poodinis/container.d b/source/poodinis/container.d index 2178dd6..c45d921 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -343,18 +343,19 @@ synchronized class DependencyContainer writeln("DEBUG: Resolving type " ~ resolveType.toString() ~ " with qualifier " ~ qualifierType.toString()); } - static if (__traits(compiles, new QualifierType())) + auto candidates = resolveType in registrations; + if (!candidates) { if (hasOption(resolveOptions, persistentResolveOptions, ResolveOption.registerBeforeResolving)) { - register!(RegistrationType, QualifierType)(); + static if (__traits(compiles, new QualifierType())) + { + register!(RegistrationType, QualifierType)(); + return resolve!(RegistrationType, QualifierType)(resolveOptions); + } } - } - auto candidates = resolveType in registrations; - if (!candidates) - { if (hasOption(resolveOptions, persistentResolveOptions, ResolveOption.noResolveException)) {