mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Deprecate calling register() with RegistationOptions in a variadic way
Variadic options will conflict when added to resolve(). To keep the interface consistent, register should follow suit. Supply options using a list of options instead.
This commit is contained in:
parent
46dddbfd46
commit
065e7111cd
|
@ -99,7 +99,14 @@ synchronized class DependencyContainer {
|
|||
* See_Also: singleInstance, newInstance, existingInstance
|
||||
*/
|
||||
public Registration register(ConcreteType)() {
|
||||
return register!(ConcreteType, ConcreteType)();
|
||||
return register!(ConcreteType, ConcreteType)([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: Use register(SuperType, ConcreteType)(RegistrationOption[]) instead
|
||||
*/
|
||||
public Registration register(SuperType, ConcreteType : SuperType)(RegistrationOption options...) {
|
||||
return register!(SuperType, ConcreteType)(options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +126,7 @@ synchronized class DependencyContainer {
|
|||
*
|
||||
* See_Also: singleInstance, newInstance, existingInstance, RegistrationOptions
|
||||
*/
|
||||
public Registration register(SuperType, ConcreteType : SuperType, RegistrationOptionsTuple...)(RegistrationOptionsTuple options) {
|
||||
public Registration register(SuperType, ConcreteType : SuperType)(RegistrationOption[] options = []) {
|
||||
TypeInfo registeredType = typeid(SuperType);
|
||||
TypeInfo_Class concreteType = typeid(ConcreteType);
|
||||
|
||||
|
@ -146,7 +153,7 @@ synchronized class DependencyContainer {
|
|||
return newRegistration;
|
||||
}
|
||||
|
||||
private bool hasOption(OptionType, OptionsTuple...)(OptionsTuple options, OptionType[] persistentOptions, OptionType option) {
|
||||
private bool hasOption(OptionType)(OptionType[] options, shared(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) {
|
||||
|
|
|
@ -497,7 +497,7 @@ version(unittest) {
|
|||
// Test registering type with option doNotAddConcreteTypeRegistration
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(TestInterface, TestClass)(RegistrationOption.doNotAddConcreteTypeRegistration);
|
||||
container.register!(TestInterface, TestClass)([RegistrationOption.doNotAddConcreteTypeRegistration]);
|
||||
|
||||
auto firstInstance = container.resolve!TestInterface;
|
||||
assertThrown!ResolveException(container.resolve!TestClass);
|
||||
|
@ -506,7 +506,15 @@ version(unittest) {
|
|||
// 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);
|
||||
container.register!(TestInterface, TestClass)([RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION]);
|
||||
|
||||
auto firstInstance = container.resolve!TestInterface;
|
||||
assertThrown!ResolveException(container.resolve!TestClass);
|
||||
}
|
||||
// Test registering type with options in the DEPRECATED way
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(TestInterface, TestClass)(RegistrationOption.doNotAddConcreteTypeRegistration);
|
||||
|
||||
auto firstInstance = container.resolve!TestInterface;
|
||||
assertThrown!ResolveException(container.resolve!TestClass);
|
||||
|
|
Loading…
Reference in a new issue