mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Rename RegistrationOptions -> RegistrationOption, deprecate usage of old name
This commit is contained in:
parent
7fba33247a
commit
ae9e0bab68
|
@ -3,6 +3,8 @@ Poodinis Changelog
|
||||||
**Version 5.0.0**
|
**Version 5.0.0**
|
||||||
* DEPRECATE ADD_CONCRETE_TYPE_REGISTRATION registration option. It basically does nothing anymore. See next point.
|
* DEPRECATE ADD_CONCRETE_TYPE_REGISTRATION registration option. It basically does nothing anymore. See next point.
|
||||||
* CHANGE adding registrations by super type always registers them by concrete type as well now. (Previously done with ADD_CONCRETE_TYPE_REGISTRATION). See DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION for the reverse behaviour.
|
* CHANGE adding registrations by super type always registers them by concrete type as well now. (Previously done with ADD_CONCRETE_TYPE_REGISTRATION). See DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION for the reverse behaviour.
|
||||||
|
* CHANGE RegistrationOptions enum name to RegistrationOption
|
||||||
|
* DEPRECATE Usage of RegistrationOptions, please use RegistrationOption instead.
|
||||||
|
|
||||||
**Version 4.0.0**
|
**Version 4.0.0**
|
||||||
* REMOVE deprecated module "dependency.d"
|
* REMOVE deprecated module "dependency.d"
|
||||||
|
|
|
@ -45,7 +45,7 @@ class RegistrationException : Exception {
|
||||||
/**
|
/**
|
||||||
* Options which influence the process of registering dependencies
|
* Options which influence the process of registering dependencies
|
||||||
*/
|
*/
|
||||||
public enum RegistrationOptions {
|
public enum RegistrationOption {
|
||||||
/**
|
/**
|
||||||
* When registering a type by its supertype, providing this option will also register
|
* When registering a type by its supertype, providing this option will also register
|
||||||
* a linked registration to the type itself.
|
* a linked registration to the type itself.
|
||||||
|
@ -77,6 +77,11 @@ public enum RegistrationOptions {
|
||||||
DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
|
DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecated: Use enum RegistrationOption instead
|
||||||
|
*/
|
||||||
|
alias RegistrationOptions = RegistrationOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The dependency container maintains all dependencies registered with it.
|
* The dependency container maintains all dependencies registered with it.
|
||||||
*
|
*
|
||||||
|
@ -149,7 +154,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, RegistrationOptions.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION)) {
|
if (!hasOption(options, RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION)) {
|
||||||
static if (!is(SuperType == ConcreteType)) {
|
static if (!is(SuperType == ConcreteType)) {
|
||||||
auto concreteTypeRegistration = register!ConcreteType;
|
auto concreteTypeRegistration = register!ConcreteType;
|
||||||
concreteTypeRegistration.linkTo(newRegistration);
|
concreteTypeRegistration.linkTo(newRegistration);
|
||||||
|
@ -160,7 +165,7 @@ synchronized class DependencyContainer {
|
||||||
return newRegistration;
|
return newRegistration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool hasOption(RegistrationOptionsTuple...)(RegistrationOptionsTuple options, RegistrationOptions option) {
|
private bool hasOption(RegistrationOptionsTuple...)(RegistrationOptionsTuple options, RegistrationOption option) {
|
||||||
foreach(presentOption ; options) {
|
foreach(presentOption ; options) {
|
||||||
if (presentOption == option) {
|
if (presentOption == option) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -435,7 +435,7 @@ version(unittest) {
|
||||||
// Test registering type with option ADD_CONCRETE_TYPE_REGISTRATION
|
// Test registering type with option ADD_CONCRETE_TYPE_REGISTRATION
|
||||||
unittest {
|
unittest {
|
||||||
shared(DependencyContainer) container = new DependencyContainer();
|
shared(DependencyContainer) container = new DependencyContainer();
|
||||||
container.register!(TestInterface, TestClass)(RegistrationOptions.ADD_CONCRETE_TYPE_REGISTRATION);
|
container.register!(TestInterface, TestClass)(RegistrationOption.ADD_CONCRETE_TYPE_REGISTRATION);
|
||||||
|
|
||||||
auto firstInstance = container.resolve!TestInterface;
|
auto firstInstance = container.resolve!TestInterface;
|
||||||
auto secondInstance = container.resolve!TestClass;
|
auto secondInstance = container.resolve!TestClass;
|
||||||
|
@ -446,7 +446,7 @@ version(unittest) {
|
||||||
// Test registering type with option DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
|
// Test registering type with option DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
|
||||||
unittest {
|
unittest {
|
||||||
shared(DependencyContainer) container = new DependencyContainer();
|
shared(DependencyContainer) container = new DependencyContainer();
|
||||||
container.register!(TestInterface, TestClass)(RegistrationOptions.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
|
container.register!(TestInterface, TestClass)(RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
|
||||||
|
|
||||||
auto firstInstance = container.resolve!TestInterface;
|
auto firstInstance = container.resolve!TestInterface;
|
||||||
assertThrown!ResolveException(container.resolve!TestClass);
|
assertThrown!ResolveException(container.resolve!TestClass);
|
||||||
|
|
Loading…
Reference in a new issue