diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index 98994d0..0a1fd11 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -17,12 +17,12 @@ module poodinis.autowire; -import poodinis.container; -import poodinis.registration; -import poodinis.factory; -import poodinis.valueinjection; +import poodinis.container : DependencyContainer, PreDestroy, ResolveException, ResolveOption; +import poodinis.registration : Registration, InstantiationContext; +import poodinis.factory : InstanceFactory, InstanceFactoryParameters, CreatesSingleton; +import poodinis.valueinjection : ValueInjector, ValueInjectionException, ValueNotAvailableException, Value, MandatoryValue; import poodinis.altphobos : isFunction; -import poodinis.imports; +import poodinis.imports : createImportsString; import std.exception : enforce; import std.string : format; diff --git a/source/poodinis/container.d b/source/poodinis/container.d index f43313b..36e36f2 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -13,13 +13,12 @@ module poodinis.container; -import poodinis.registration; -import poodinis.autowire; -import poodinis.context; -import poodinis.factory; -import poodinis.valueinjection; +import poodinis.registration : Registration, singleInstance, toConcreteTypeListString; +import poodinis.autowire : AutowiredRegistration, AutowireInstantiationContext; +import poodinis.factory : ConstructorInjectingInstanceFactory; +import poodinis.valueinjection : ValueInjectionException; import poodinis.altphobos : isFunction; -import poodinis.imports; +import poodinis.imports : createImportsString; import std.string : format; import std.algorithm: canFind; diff --git a/source/poodinis/context.d b/source/poodinis/context.d index b80841a..a208259 100644 --- a/source/poodinis/context.d +++ b/source/poodinis/context.d @@ -13,12 +13,12 @@ module poodinis.context; -import poodinis.container; -import poodinis.registration; -import poodinis.factory; -import poodinis.autowire; +import poodinis.container : DependencyContainer; +import poodinis.registration : Registration, existingInstance; +import poodinis.factory : CreatesSingleton, InstanceFactoryParameters; +import poodinis.autowire : autowire; -import std.traits; +import std.traits : hasUDA, ReturnType; class ApplicationContext { public void registerDependencies(shared(DependencyContainer) container) {} diff --git a/source/poodinis/factory.d b/source/poodinis/factory.d index 72cd54f..972c335 100644 --- a/source/poodinis/factory.d +++ b/source/poodinis/factory.d @@ -11,14 +11,17 @@ module poodinis.factory; -import poodinis.container; -import poodinis.imports; +import poodinis.container : DependencyContainer; +import poodinis.imports : createImportsString; -import std.typecons; -import std.exception; -import std.traits; -import std.string; -import std.stdio; +import std.typecons : Flag; +import std.exception : enforce; +import std.traits : Parameters, isBuiltinType, fullyQualifiedName; +import std.string : format; + +debug { + import std.stdio : writeln; +} alias CreatesSingleton = Flag!"CreatesSingleton"; alias InstanceFactoryMethod = Object delegate(); @@ -89,18 +92,22 @@ class InstanceFactory { } private void printDebugUseExistingInstance() { - if (_factoryParameters.instanceType !is null) { - writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); - } else { - writeln("DEBUG: Existing instance returned from custom factory method"); + debug { + if (_factoryParameters.instanceType !is null) { + writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); + } else { + writeln("DEBUG: Existing instance returned from custom factory method"); + } } } private void printDebugCreateNewInstance() { - if (_factoryParameters.instanceType !is null) { - writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); - } else { - writeln("DEBUG: Creating new instance from custom factory method"); + debug { + if (_factoryParameters.instanceType !is null) { + writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); + } else { + writeln("DEBUG: Creating new instance from custom factory method"); + } } } diff --git a/source/poodinis/imports.d b/source/poodinis/imports.d index 750e602..44ff7f2 100644 --- a/source/poodinis/imports.d +++ b/source/poodinis/imports.d @@ -11,8 +11,8 @@ module poodinis.imports; -import std.meta; -import std.traits; +import std.meta : staticIndexOf; +import std.traits : moduleName, TemplateArgsOf, isBuiltinType; public static string createImportsString(Type, ParentTypeList...)() { string imports = `import ` ~ moduleName!Type ~ `;`; diff --git a/source/poodinis/package.d b/source/poodinis/package.d index 54df0a0..2c04f43 100644 --- a/source/poodinis/package.d +++ b/source/poodinis/package.d @@ -11,9 +11,12 @@ module poodinis; +public import poodinis.altphobos; public import poodinis.autowire; public import poodinis.container; -public import poodinis.registration; public import poodinis.context; public import poodinis.factory; +public import poodinis.imports; +public import poodinis.polyfill; +public import poodinis.registration; public import poodinis.valueinjection; diff --git a/source/poodinis/polyfill.d b/source/poodinis/polyfill.d index a9ef1fe..7ea5052 100644 --- a/source/poodinis/polyfill.d +++ b/source/poodinis/polyfill.d @@ -26,19 +26,36 @@ module poodinis.polyfill; import std.exception; -import std.traits; static if (!__traits(compiles, basicExceptionCtors)) { mixin template basicExceptionCtors() { - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) @safe pure nothrow + /++ + Params: + msg = The message for the exception. + file = The file where the exception occurred. + line = The line number where the exception occurred. + next = The previous exception in the chain of exceptions, if any. + +/ + this(string msg, string file = __FILE__, size_t line = __LINE__, + Throwable next = null) @nogc @safe pure nothrow { super(msg, file, line, next); } - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) @safe pure nothrow + /++ + Params: + msg = The message for the exception. + next = The previous exception in the chain of exceptions. + file = The file where the exception occurred. + line = The line number where the exception occurred. + +/ + this(string msg, Throwable next, string file = __FILE__, + size_t line = __LINE__) @nogc @safe pure nothrow { super(msg, file, line, next); } } +} else { + public import std.exception : basicExceptionCtors; } diff --git a/source/poodinis/registration.d b/source/poodinis/registration.d index a50a93a..1320ee9 100644 --- a/source/poodinis/registration.d +++ b/source/poodinis/registration.d @@ -13,8 +13,8 @@ module poodinis.registration; -import poodinis.container; -import poodinis.factory; +import poodinis.container : DependencyContainer; +import poodinis.factory : InstanceFactory, InstanceEventHandler, InstanceCreationException, InstanceFactoryParameters, CreatesSingleton; class Registration { private TypeInfo _registeredType = null; diff --git a/source/poodinis/valueinjection.d b/source/poodinis/valueinjection.d index b281d90..7f5340b 100644 --- a/source/poodinis/valueinjection.d +++ b/source/poodinis/valueinjection.d @@ -11,9 +11,9 @@ */ module poodinis.valueinjection; -import std.exception; -import std.string; -import poodinis.polyfill; +import poodinis.polyfill : basicExceptionCtors; + +import std.string : format; /** * Thrown when something goes wrong during value injection.