mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add global setting for disabling type validity
This commit is contained in:
parent
423f21230a
commit
da1f604ef7
|
@ -28,6 +28,16 @@ class Container {
|
||||||
|
|
||||||
private static Registration[TypeInfo] registrations;
|
private static Registration[TypeInfo] registrations;
|
||||||
|
|
||||||
|
private static bool _globalTypeValidityCheckEnabled = true;
|
||||||
|
|
||||||
|
@property public static void globalTypeValidityCheckEnabled(bool enabled) {
|
||||||
|
_globalTypeValidityCheckEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property public static bool globalTypeValidityCheckEnabled() {
|
||||||
|
return _globalTypeValidityCheckEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
private this() {
|
private this() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +49,7 @@ class Container {
|
||||||
TypeInfo registeredType = typeid(InterfaceType);
|
TypeInfo registeredType = typeid(InterfaceType);
|
||||||
TypeInfo_Class instantiatableType = typeid(ConcreteType);
|
TypeInfo_Class instantiatableType = typeid(ConcreteType);
|
||||||
|
|
||||||
if (checkTypeValidity) {
|
if (globalTypeValidityCheckEnabled && checkTypeValidity) {
|
||||||
checkValidity!(InterfaceType)(registeredType, instantiatableType);
|
checkValidity!(InterfaceType)(registeredType, instantiatableType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,4 +55,14 @@ version(unittest) {
|
||||||
assertThrown!ResolveException(Container.resolve!(TestClass)(), "Resolving non-registered type does not fail");
|
assertThrown!ResolveException(Container.resolve!(TestClass)(), "Resolving non-registered type does not fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest {
|
||||||
|
// Test register unrelated class with disable global type validity disabled
|
||||||
|
bool currentSetting = Container.globalTypeValidityCheckEnabled;
|
||||||
|
Container.globalTypeValidityCheckEnabled = false;
|
||||||
|
|
||||||
|
assertNotThrown!RegistrationException(Container.register!(UnrelatedClass, TestClass)(), "Registering unrelated types while disabling global type validity fails");
|
||||||
|
|
||||||
|
Container.globalTypeValidityCheckEnabled = currentSetting;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue