Add setting persistent resolve options

This commit is contained in:
Mike Bierlee 2016-02-03 23:13:36 +01:00
parent a1cbd9650a
commit 5d9ac73418
3 changed files with 34 additions and 2 deletions

View file

@ -1,7 +1,7 @@
Poodinis Changelog Poodinis Changelog
================== ==================
**Version NEXT** **Version NEXT**
* ADD setting persistent registration options * ADD setting persistent registration and resolve options
* DEPRECATE DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION, use doNotAddConcreteTypeRegistration instead * DEPRECATE DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION, use doNotAddConcreteTypeRegistration instead
* DEPRECATE supplying register()'s registration options as variadic arguments. Use register(SuperType, ConcreteType)(RegistrationOption[]) instead. * DEPRECATE supplying register()'s registration options as variadic arguments. Use register(SuperType, ConcreteType)(RegistrationOption[]) instead.
* ADD resolve options to container resolve() * ADD resolve options to container resolve()

View file

@ -417,7 +417,7 @@ synchronized class DependencyContainer {
/** /**
* Apply persistent registration options which will be used everytime register() is called. * Apply persistent registration options which will be used everytime register() is called.
*/ */
public void setPersistentRegistrationOptions(RegistrationOptionsTuple...)(RegistrationOptionsTuple registrationOptions) { public void setPersistentRegistrationOptions(OptionsTuple...)(OptionsTuple registrationOptions) {
unsetPersistentRegistrationOptions(); unsetPersistentRegistrationOptions();
foreach (option; registrationOptions) { foreach (option; registrationOptions) {
persistentRegistrationOptions ~= option; persistentRegistrationOptions ~= option;
@ -431,4 +431,21 @@ synchronized class DependencyContainer {
persistentRegistrationOptions = []; persistentRegistrationOptions = [];
} }
/**
* Apply persistent resolve options which will be used everytime resolve() is called.
*/
public void setPersistentResolveOptions(OptionsTuple...)(OptionsTuple resolveOptions) {
unsetPersistentResolveOptions();
foreach (option; resolveOptions) {
persistentResolveOptions ~= option;
}
}
/**
* Unsets all applied registration options
*/
public void unsetPersistentResolveOptions() {
persistentResolveOptions = [];
}
} }

View file

@ -634,4 +634,19 @@ version(unittest) {
container.resolve!(TestInterface, TestClass)([ResolveOption.registerBeforeResolving]); container.resolve!(TestInterface, TestClass)([ResolveOption.registerBeforeResolving]);
container.resolve!TestClass; container.resolve!TestClass;
} }
// Test set persistent resolve options
unittest {
shared(DependencyContainer) container = new DependencyContainer();
container.setPersistentResolveOptions(ResolveOption.registerBeforeResolving);
container.resolve!TestClass;
}
// Test unset persistent resolve options
unittest {
shared(DependencyContainer) container = new DependencyContainer();
container.setPersistentResolveOptions(ResolveOption.registerBeforeResolving);
container.unsetPersistentResolveOptions();
assertThrown!ResolveException(container.resolve!TestClass);
}
} }