mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Always register concrete type when registering type by supertype by default.
This deprecates ADD_CONCRETE_TYPE_REGISTRATION (see DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION for reverse configuration). This also means you do not need to use qualifiers when registering single type of super type by super type.
This commit is contained in:
parent
8c103df7e5
commit
da16513a8d
|
@ -1,5 +1,9 @@
|
||||||
Poodinis Changelog
|
Poodinis Changelog
|
||||||
==================
|
==================
|
||||||
|
** Next version**
|
||||||
|
* 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.
|
||||||
|
|
||||||
**Version 4.0.0**
|
**Version 4.0.0**
|
||||||
* REMOVE deprecated module "dependency.d"
|
* REMOVE deprecated module "dependency.d"
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,17 @@ public enum RegistrationOptions {
|
||||||
*
|
*
|
||||||
* assert(firstCat is secondCat);
|
* assert(firstCat is secondCat);
|
||||||
* ---
|
* ---
|
||||||
|
*
|
||||||
|
* Deprecated: ADD_CONCRETE_TYPE_REGISTRATION behaviour is default now. If you want to reverse to happen, use DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION.
|
||||||
*/
|
*/
|
||||||
ADD_CONCRETE_TYPE_REGISTRATION
|
|
||||||
|
ADD_CONCRETE_TYPE_REGISTRATION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,12 +149,10 @@ 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.ADD_CONCRETE_TYPE_REGISTRATION)) {
|
if (!hasOption(options, RegistrationOptions.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);
|
||||||
} else {
|
|
||||||
throw new RegistrationException("Option ADD_CONCRETE_TYPE_REGISTRATION cannot be used when registering a concrete type registration", concreteType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -443,10 +443,24 @@ version(unittest) {
|
||||||
assert(firstInstance is secondInstance);
|
assert(firstInstance is secondInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test registering concrete type with option 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();
|
||||||
assertThrown!RegistrationException(container.register!(TestClass, TestClass)(RegistrationOptions.ADD_CONCRETE_TYPE_REGISTRATION));
|
container.register!(TestInterface, TestClass)(RegistrationOptions.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION);
|
||||||
|
|
||||||
|
auto firstInstance = container.resolve!TestInterface;
|
||||||
|
assertThrown!ResolveException(container.resolve!TestClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test registering type will register by contrete type by default
|
||||||
|
unittest {
|
||||||
|
shared(DependencyContainer) container = new DependencyContainer();
|
||||||
|
container.register!(TestInterface, TestClass);
|
||||||
|
|
||||||
|
auto firstInstance = container.resolve!TestInterface;
|
||||||
|
auto secondInstance = container.resolve!TestClass;
|
||||||
|
|
||||||
|
assert(firstInstance is secondInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test resolving all registrations to an interface
|
// Test resolving all registrations to an interface
|
||||||
|
|
Loading…
Reference in a new issue