Skip validity check on registering concrete type

This commit is contained in:
Mike Bierlee 2014-05-20 01:12:15 +02:00
parent b18b6ed49c
commit 464abd9cb0
2 changed files with 18 additions and 1 deletions

View file

@ -40,7 +40,7 @@ class Container {
} }
public Registration register(ConcreteType)() { public Registration register(ConcreteType)() {
return register!(ConcreteType, ConcreteType)(); return register!(ConcreteType, ConcreteType)(false);
} }
public Registration register(InterfaceType, ConcreteType)(bool checkTypeValidity = true) { public Registration register(InterfaceType, ConcreteType)(bool checkTypeValidity = true) {

View file

@ -12,6 +12,12 @@ version(unittest) {
class UnrelatedClass{ class UnrelatedClass{
} }
class FailOnCreationClass {
this() {
throw new Exception("This class should not be instantiated");
}
}
unittest { unittest {
// Test register concrete type // Test register concrete type
auto container = new Container(); auto container = new Container();
@ -77,4 +83,15 @@ version(unittest) {
assert(instance1 is instance2, "getInstance does not return the same instance"); 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");
}
}
} }