diff --git a/CHANGES.md b/CHANGES.md index 0488f01..f9ec50e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ Poodinis Changelog ================== +**Version NEXT** +* FIX nullpointer exception in instance factory when debugging with poodinisVerbose + **Version 7.0.1** * FIX codegeneration of constructor injection factories for constructors with dependencies from foreign modules, such as modules from other libraries (Issue #12). diff --git a/source/poodinis/factory.d b/source/poodinis/factory.d index 01375e1..4341d88 100644 --- a/source/poodinis/factory.d +++ b/source/poodinis/factory.d @@ -67,20 +67,36 @@ class InstanceFactory { public Object getInstance() { if (_factoryParameters.createsSingleton && instance !is null) { debug(poodinisVerbose) { - writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); + printDebugUseExistingInstance(); } return instance; } debug(poodinisVerbose) { - writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); + printDebugCreateNewInstance(); } instance = _factoryParameters.factoryMethod(); return instance; } + private void printDebugUseExistingInstance() { + if (_factoryParameters.instanceType !is null) { + writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); + } else { + writeln("DEBUG: Existing instance returned from custom factory method"); + } + } + + private void printDebugCreateNewInstance() { + if (_factoryParameters.instanceType !is null) { + writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); + } else { + writeln("DEBUG: Creating new instance from custom factory method"); + } + } + protected Object createInstance() { enforce!InstanceCreationException(_factoryParameters.instanceType, "Instance type is not defined, cannot create instance without knowing its type."); return _factoryParameters.instanceType.create();