From 464abd9cb0acec3f7f0e48c60cdbe6abc2d7afa8 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Tue, 20 May 2014 01:12:15 +0200 Subject: [PATCH] Skip validity check on registering concrete type --- source/poodinis/container.d | 2 +- test/poodinis/containertest.d | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/poodinis/container.d b/source/poodinis/container.d index fb5622d..09638a2 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -40,7 +40,7 @@ class Container { } public Registration register(ConcreteType)() { - return register!(ConcreteType, ConcreteType)(); + return register!(ConcreteType, ConcreteType)(false); } public Registration register(InterfaceType, ConcreteType)(bool checkTypeValidity = true) { diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index d3a1569..ac93206 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -12,6 +12,12 @@ version(unittest) { class UnrelatedClass{ } + class FailOnCreationClass { + this() { + throw new Exception("This class should not be instantiated"); + } + } + unittest { // Test register concrete type auto container = new Container(); @@ -77,4 +83,15 @@ version(unittest) { assert(instance1 is instance2, "getInstance does not return the same instance"); } + unittest { + // Test registering concrete type does not do a validity check + auto container = new Container(); + assert(container.typeValidityCheckEnabled); + try { + container.register!(FailOnCreationClass)(); + } catch (Exception) { + assert(false, "Registering concrete type executed a validity check"); + } + } + } \ No newline at end of file