diff --git a/CHANGES.md b/CHANGES.md index 174e4e1..60ca11c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ Poodinis Changelog ================== +**Version 8.1.0-beta.4** +* ADD compilation failure when trying to register a class by a supertype it does not inherit from. (#31) + **Version 8.1.0-beta.3** * CHANGE injection initializers to be defined as a registration scope instead of via Container.register(). See initializedBy(). * ADD initializedOnceBy() to create singleton instances via injection initializer. diff --git a/source/poodinis/container.d b/source/poodinis/container.d index eca6446..a25d838 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -25,6 +25,7 @@ import std.string; import std.algorithm; import std.concurrency; import std.traits; +import std.meta : AliasSeq; debug { import std.stdio; @@ -194,6 +195,12 @@ synchronized class DependencyContainer { return newRegistration; } + public Registration register(SuperType, ConcreteType)(RegistrationOption options = RegistrationOption.none) + if (!is(SuperType == ConcreteType) && !is(BaseTypeTuple!ConcreteType == AliasSeq!(Object, SuperType)) && !is(BaseTypeTuple!ConcreteType == AliasSeq!(SuperType))) { + pragma(msg, "Cannot register dependency: ", ConcreteType, " is not derived from ", SuperType); + static assert(0, "Cannot register dependency"); + } + private bool hasOption(OptionType)(OptionType options, OptionType persistentOptions, OptionType option) { return ((options | persistentOptions) & option) != 0; }