mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Change imports to only include used symbols
This commit is contained in:
parent
6ab7795463
commit
5e9774b96a
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -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,20 +92,24 @@ class InstanceFactory {
|
|||
}
|
||||
|
||||
private void printDebugUseExistingInstance() {
|
||||
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() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Object createInstance() {
|
||||
enforce!InstanceCreationException(_factoryParameters.instanceType, "Instance type is not defined, cannot create instance without knowing its type.");
|
||||
|
|
|
@ -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 ~ `;`;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue