From 5a66bdc26aa18fc336b7a36a5b8404878495db4f Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Thu, 27 Oct 2022 02:26:44 +0300 Subject: [PATCH] Fix registerOnResolve not working for classes that have no default constructor It might be that these want to make use of constructor injection instead --- CHANGES.md | 1 + source/poodinis/container.d | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7e74e5f..e2a4d52 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ Poodinis Changelog **Version NEXT** * FIX unnecessary re-registration of types when registerBeforeResolving is specified. +* FIX registerOnResolve not working for classes that have no default constructor **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 c45d921..ed16a2f 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -184,7 +184,6 @@ synchronized class DependencyContainer SuperType)(RegistrationOption options = RegistrationOption.none) if (!is(ConcreteType == struct)) { - TypeInfo registeredType = typeid(SuperType); TypeInfo_Class concreteType = typeid(ConcreteType); @@ -346,10 +345,10 @@ synchronized class DependencyContainer auto candidates = resolveType in registrations; if (!candidates) { - if (hasOption(resolveOptions, persistentResolveOptions, - ResolveOption.registerBeforeResolving)) + static if (is(typeof(typeid(QualifierType)) == TypeInfo_Class) && !__traits(isAbstractClass, QualifierType)) { - static if (__traits(compiles, new QualifierType())) + if (hasOption(resolveOptions, persistentResolveOptions, ResolveOption + .registerBeforeResolving)) { register!(RegistrationType, QualifierType)(); return resolve!(RegistrationType, QualifierType)(resolveOptions);