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:
Mike Bierlee 2016-02-03 22:16:23 +01:00
parent 46dddbfd46
commit 065e7111cd
2 changed files with 20 additions and 5 deletions

View file

@ -99,7 +99,14 @@ synchronized class DependencyContainer {
* See_Also: singleInstance, newInstance, existingInstance * See_Also: singleInstance, newInstance, existingInstance
*/ */
public Registration register(ConcreteType)() { 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 * 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 registeredType = typeid(SuperType);
TypeInfo_Class concreteType = typeid(ConcreteType); TypeInfo_Class concreteType = typeid(ConcreteType);
@ -146,7 +153,7 @@ synchronized class DependencyContainer {
return newRegistration; 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) { foreach (presentOption; persistentOptions) {
// DEPRECATED LEGACY COMPATIBILITY - REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE (SOON) // DEPRECATED LEGACY COMPATIBILITY - REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE (SOON)
if (presentOption == RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION) { if (presentOption == RegistrationOption.DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION) {

View file

@ -497,7 +497,7 @@ version(unittest) {
// Test registering type with option doNotAddConcreteTypeRegistration // Test registering type with option doNotAddConcreteTypeRegistration
unittest { unittest {
shared(DependencyContainer) container = new DependencyContainer(); shared(DependencyContainer) container = new DependencyContainer();
container.register!(TestInterface, TestClass)(RegistrationOption.doNotAddConcreteTypeRegistration); container.register!(TestInterface, TestClass)([RegistrationOption.doNotAddConcreteTypeRegistration]);
auto firstInstance = container.resolve!TestInterface; auto firstInstance = container.resolve!TestInterface;
assertThrown!ResolveException(container.resolve!TestClass); assertThrown!ResolveException(container.resolve!TestClass);
@ -506,7 +506,15 @@ version(unittest) {
// Test registering type with option DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION (DEPRECATED) // 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]);
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; auto firstInstance = container.resolve!TestInterface;
assertThrown!ResolveException(container.resolve!TestClass); assertThrown!ResolveException(container.resolve!TestClass);