Deprecate RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION in favor of RegistrationOption.doNotAddConcreteTypeRegistration

This commit is contained in:
Mike Bierlee 2016-02-03 21:38:06 +01:00
parent def5ec2e88
commit 46dddbfd46
3 changed files with 31 additions and 4 deletions

View file

@ -2,6 +2,7 @@ Poodinis Changelog
==================
**Version NEXT**
* ADD setting persistent registration options
* DEPRECATE DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION, use doNotAddConcreteTypeRegistration instead
**Version 6.0.0**
* CHANGE registration scopes are replaced by a single factory implementation. If you were not doing anything with the internal scope mechanism, you

View file

@ -51,6 +51,13 @@ public enum RegistrationOption {
* Prevent a concrete type being registered on itself. With this option you will always need
* to use the supertype as the type of the dependency.
*/
doNotAddConcreteTypeRegistration,
/**
* Prevent a concrete type being registered on itself. With this option you will always need
* to use the supertype as the type of the dependency.
* @deprecated use doNotAddConcreteTypeRegistration instead
*/
DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
}
@ -128,7 +135,7 @@ synchronized class DependencyContainer {
auto newRegistration = new AutowiredRegistration!ConcreteType(registeredType, this);
newRegistration.singleInstance();
if (!hasOption(options, persistentRegistrationOptions, RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION)) {
if (!hasOption(options, persistentRegistrationOptions, RegistrationOption.doNotAddConcreteTypeRegistration)) {
static if (!is(SuperType == ConcreteType)) {
auto concreteTypeRegistration = register!ConcreteType;
concreteTypeRegistration.linkTo(newRegistration);
@ -141,12 +148,22 @@ synchronized class DependencyContainer {
private bool hasOption(OptionType, OptionsTuple...)(OptionsTuple options, OptionType[] persistentOptions, OptionType option) {
foreach (presentOption; persistentOptions) {
// DEPRECATED LEGACY COMPATIBILITY - REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE (SOON)
if (presentOption == RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION) {
presentOption = RegistrationOption.doNotAddConcreteTypeRegistration;
}
if (presentOption == option) {
return true;
}
}
foreach(presentOption ; options) {
// DEPRECATED LEGACY COMPATIBILITY - REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE (SOON)
if (presentOption == RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION) {
presentOption = RegistrationOption.doNotAddConcreteTypeRegistration;
}
if (presentOption == option) {
return true;
}

View file

@ -494,7 +494,16 @@ version(unittest) {
assert(expectedTestClass is actualTestClass, "Instance resolved in main thread is not the one resolved in thread");
}
// Test registering type with option DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
// Test registering type with option doNotAddConcreteTypeRegistration
unittest {
shared(DependencyContainer) container = new DependencyContainer();
container.register!(TestInterface, TestClass)(RegistrationOption.doNotAddConcreteTypeRegistration);
auto firstInstance = container.resolve!TestInterface;
assertThrown!ResolveException(container.resolve!TestClass);
}
// Test registering type with option DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION (DEPRECATED)
unittest {
shared(DependencyContainer) container = new DependencyContainer();
container.register!(TestInterface, TestClass)(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
@ -589,7 +598,7 @@ version(unittest) {
// Test set persistent registration options
unittest {
shared(DependencyContainer) container = new DependencyContainer();
container.setPersistentRegistrationOptions(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
container.setPersistentRegistrationOptions(RegistrationOption.doNotAddConcreteTypeRegistration);
container.register!(TestInterface, TestClass);
assertThrown!ResolveException(container.resolve!TestClass);
}
@ -597,7 +606,7 @@ version(unittest) {
// Test unset persistent registration options
unittest {
shared(DependencyContainer) container = new DependencyContainer();
container.setPersistentRegistrationOptions(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
container.setPersistentRegistrationOptions(RegistrationOption.doNotAddConcreteTypeRegistration);
container.unsetPersistentRegistrationOptions();
container.register!(TestInterface, TestClass);
container.resolve!TestClass;