mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Deprecate RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION in favor of RegistrationOption.doNotAddConcreteTypeRegistration
This commit is contained in:
parent
def5ec2e88
commit
46dddbfd46
|
@ -2,6 +2,7 @@ Poodinis Changelog
|
||||||
==================
|
==================
|
||||||
**Version NEXT**
|
**Version NEXT**
|
||||||
* ADD setting persistent registration options
|
* ADD setting persistent registration options
|
||||||
|
* DEPRECATE DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION, use doNotAddConcreteTypeRegistration instead
|
||||||
|
|
||||||
**Version 6.0.0**
|
**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
|
* CHANGE registration scopes are replaced by a single factory implementation. If you were not doing anything with the internal scope mechanism, you
|
||||||
|
|
|
@ -51,6 +51,13 @@ public enum RegistrationOption {
|
||||||
* Prevent a concrete type being registered on itself. With this option you will always need
|
* 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.
|
* 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
|
DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +135,7 @@ synchronized class DependencyContainer {
|
||||||
auto newRegistration = new AutowiredRegistration!ConcreteType(registeredType, this);
|
auto newRegistration = new AutowiredRegistration!ConcreteType(registeredType, this);
|
||||||
newRegistration.singleInstance();
|
newRegistration.singleInstance();
|
||||||
|
|
||||||
if (!hasOption(options, persistentRegistrationOptions, RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION)) {
|
if (!hasOption(options, persistentRegistrationOptions, RegistrationOption.doNotAddConcreteTypeRegistration)) {
|
||||||
static if (!is(SuperType == ConcreteType)) {
|
static if (!is(SuperType == ConcreteType)) {
|
||||||
auto concreteTypeRegistration = register!ConcreteType;
|
auto concreteTypeRegistration = register!ConcreteType;
|
||||||
concreteTypeRegistration.linkTo(newRegistration);
|
concreteTypeRegistration.linkTo(newRegistration);
|
||||||
|
@ -141,12 +148,22 @@ synchronized class DependencyContainer {
|
||||||
|
|
||||||
private bool hasOption(OptionType, OptionsTuple...)(OptionsTuple options, OptionType[] persistentOptions, OptionType option) {
|
private bool hasOption(OptionType, OptionsTuple...)(OptionsTuple options, OptionType[] persistentOptions, OptionType option) {
|
||||||
foreach (presentOption; persistentOptions) {
|
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) {
|
if (presentOption == option) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(presentOption ; options) {
|
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) {
|
if (presentOption == option) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,7 +494,16 @@ version(unittest) {
|
||||||
assert(expectedTestClass is actualTestClass, "Instance resolved in main thread is not the one resolved in thread");
|
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 {
|
unittest {
|
||||||
shared(DependencyContainer) container = new DependencyContainer();
|
shared(DependencyContainer) container = new DependencyContainer();
|
||||||
container.register!(TestInterface, TestClass)(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
|
container.register!(TestInterface, TestClass)(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
|
||||||
|
@ -589,7 +598,7 @@ version(unittest) {
|
||||||
// Test set persistent registration options
|
// Test set persistent registration options
|
||||||
unittest {
|
unittest {
|
||||||
shared(DependencyContainer) container = new DependencyContainer();
|
shared(DependencyContainer) container = new DependencyContainer();
|
||||||
container.setPersistentRegistrationOptions(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
|
container.setPersistentRegistrationOptions(RegistrationOption.doNotAddConcreteTypeRegistration);
|
||||||
container.register!(TestInterface, TestClass);
|
container.register!(TestInterface, TestClass);
|
||||||
assertThrown!ResolveException(container.resolve!TestClass);
|
assertThrown!ResolveException(container.resolve!TestClass);
|
||||||
}
|
}
|
||||||
|
@ -597,7 +606,7 @@ version(unittest) {
|
||||||
// Test unset persistent registration options
|
// Test unset persistent registration options
|
||||||
unittest {
|
unittest {
|
||||||
shared(DependencyContainer) container = new DependencyContainer();
|
shared(DependencyContainer) container = new DependencyContainer();
|
||||||
container.setPersistentRegistrationOptions(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
|
container.setPersistentRegistrationOptions(RegistrationOption.doNotAddConcreteTypeRegistration);
|
||||||
container.unsetPersistentRegistrationOptions();
|
container.unsetPersistentRegistrationOptions();
|
||||||
container.register!(TestInterface, TestClass);
|
container.register!(TestInterface, TestClass);
|
||||||
container.resolve!TestClass;
|
container.resolve!TestClass;
|
||||||
|
|
Loading…
Reference in a new issue