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