Skip to content

Commit

Permalink
Rename RegistrationOptions -> RegistrationOption, deprecate usage of …
Browse files Browse the repository at this point in the history
…old name
  • Loading branch information
Mike Bierlee committed Sep 26, 2015
1 parent 7fba332 commit ae9e0ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Poodinis Changelog
**Version 5.0.0**
* 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 RegistrationOptions enum name to RegistrationOption
* DEPRECATE Usage of RegistrationOptions, please use RegistrationOption instead.

**Version 4.0.0**
* REMOVE deprecated module "dependency.d"
Expand Down
11 changes: 8 additions & 3 deletions source/poodinis/container.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RegistrationException : Exception {
/**
* 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
* a linked registration to the type itself.
Expand Down Expand Up @@ -77,6 +77,11 @@ public enum RegistrationOptions {
DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
}

/**
* Deprecated: Use enum RegistrationOption instead
*/
alias RegistrationOptions = RegistrationOption;

/**
* The dependency container maintains all dependencies registered with it.
*
Expand Down Expand Up @@ -149,7 +154,7 @@ synchronized class DependencyContainer {
auto newRegistration = new AutowiredRegistration!ConcreteType(registeredType, this);
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)) {
auto concreteTypeRegistration = register!ConcreteType;
concreteTypeRegistration.linkTo(newRegistration);
Expand All @@ -160,7 +165,7 @@ synchronized class DependencyContainer {
return newRegistration;
}

private bool hasOption(RegistrationOptionsTuple...)(RegistrationOptionsTuple options, RegistrationOptions option) {
private bool hasOption(RegistrationOptionsTuple...)(RegistrationOptionsTuple options, RegistrationOption option) {
foreach(presentOption ; options) {
if (presentOption == option) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions test/poodinis/containertest.d
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ version(unittest) {
// Test registering type with option ADD_CONCRETE_TYPE_REGISTRATION
unittest {
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 secondInstance = container.resolve!TestClass;
Expand All @@ -446,7 +446,7 @@ version(unittest) {
// Test registering type with option DO_NOT_ADD_CONCRETE_TYPE_REGISTRATION
unittest {
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;
assertThrown!ResolveException(container.resolve!TestClass);
Expand Down

0 comments on commit ae9e0ba

Please sign in to comment.