Change imports to only include used symbols

This commit is contained in:
Mike Bierlee 2021-05-01 21:40:25 +03:00
parent 6ab7795463
commit 5e9774b96a
9 changed files with 68 additions and 42 deletions

View file

@ -17,12 +17,12 @@
module poodinis.autowire; module poodinis.autowire;
import poodinis.container; import poodinis.container : DependencyContainer, PreDestroy, ResolveException, ResolveOption;
import poodinis.registration; import poodinis.registration : Registration, InstantiationContext;
import poodinis.factory; import poodinis.factory : InstanceFactory, InstanceFactoryParameters, CreatesSingleton;
import poodinis.valueinjection; import poodinis.valueinjection : ValueInjector, ValueInjectionException, ValueNotAvailableException, Value, MandatoryValue;
import poodinis.altphobos : isFunction; import poodinis.altphobos : isFunction;
import poodinis.imports; import poodinis.imports : createImportsString;
import std.exception : enforce; import std.exception : enforce;
import std.string : format; import std.string : format;

View file

@ -13,13 +13,12 @@
module poodinis.container; module poodinis.container;
import poodinis.registration; import poodinis.registration : Registration, singleInstance, toConcreteTypeListString;
import poodinis.autowire; import poodinis.autowire : AutowiredRegistration, AutowireInstantiationContext;
import poodinis.context; import poodinis.factory : ConstructorInjectingInstanceFactory;
import poodinis.factory; import poodinis.valueinjection : ValueInjectionException;
import poodinis.valueinjection;
import poodinis.altphobos : isFunction; import poodinis.altphobos : isFunction;
import poodinis.imports; import poodinis.imports : createImportsString;
import std.string : format; import std.string : format;
import std.algorithm: canFind; import std.algorithm: canFind;

View file

@ -13,12 +13,12 @@
module poodinis.context; module poodinis.context;
import poodinis.container; import poodinis.container : DependencyContainer;
import poodinis.registration; import poodinis.registration : Registration, existingInstance;
import poodinis.factory; import poodinis.factory : CreatesSingleton, InstanceFactoryParameters;
import poodinis.autowire; import poodinis.autowire : autowire;
import std.traits; import std.traits : hasUDA, ReturnType;
class ApplicationContext { class ApplicationContext {
public void registerDependencies(shared(DependencyContainer) container) {} public void registerDependencies(shared(DependencyContainer) container) {}

View file

@ -11,14 +11,17 @@
module poodinis.factory; module poodinis.factory;
import poodinis.container; import poodinis.container : DependencyContainer;
import poodinis.imports; import poodinis.imports : createImportsString;
import std.typecons; import std.typecons : Flag;
import std.exception; import std.exception : enforce;
import std.traits; import std.traits : Parameters, isBuiltinType, fullyQualifiedName;
import std.string; import std.string : format;
import std.stdio;
debug {
import std.stdio : writeln;
}
alias CreatesSingleton = Flag!"CreatesSingleton"; alias CreatesSingleton = Flag!"CreatesSingleton";
alias InstanceFactoryMethod = Object delegate(); alias InstanceFactoryMethod = Object delegate();
@ -89,18 +92,22 @@ class InstanceFactory {
} }
private void printDebugUseExistingInstance() { private void printDebugUseExistingInstance() {
if (_factoryParameters.instanceType !is null) { debug {
writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); if (_factoryParameters.instanceType !is null) {
} else { writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString()));
writeln("DEBUG: Existing instance returned from custom factory method"); } else {
writeln("DEBUG: Existing instance returned from custom factory method");
}
} }
} }
private void printDebugCreateNewInstance() { private void printDebugCreateNewInstance() {
if (_factoryParameters.instanceType !is null) { debug {
writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); if (_factoryParameters.instanceType !is null) {
} else { writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString()));
writeln("DEBUG: Creating new instance from custom factory method"); } else {
writeln("DEBUG: Creating new instance from custom factory method");
}
} }
} }

View file

@ -11,8 +11,8 @@
module poodinis.imports; module poodinis.imports;
import std.meta; import std.meta : staticIndexOf;
import std.traits; import std.traits : moduleName, TemplateArgsOf, isBuiltinType;
public static string createImportsString(Type, ParentTypeList...)() { public static string createImportsString(Type, ParentTypeList...)() {
string imports = `import ` ~ moduleName!Type ~ `;`; string imports = `import ` ~ moduleName!Type ~ `;`;

View file

@ -11,9 +11,12 @@
module poodinis; module poodinis;
public import poodinis.altphobos;
public import poodinis.autowire; public import poodinis.autowire;
public import poodinis.container; public import poodinis.container;
public import poodinis.registration;
public import poodinis.context; public import poodinis.context;
public import poodinis.factory; public import poodinis.factory;
public import poodinis.imports;
public import poodinis.polyfill;
public import poodinis.registration;
public import poodinis.valueinjection; public import poodinis.valueinjection;

View file

@ -26,19 +26,36 @@
module poodinis.polyfill; module poodinis.polyfill;
import std.exception; import std.exception;
import std.traits;
static if (!__traits(compiles, basicExceptionCtors)) { static if (!__traits(compiles, basicExceptionCtors)) {
mixin template 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); 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); super(msg, file, line, next);
} }
} }
} else {
public import std.exception : basicExceptionCtors;
} }

View file

@ -13,8 +13,8 @@
module poodinis.registration; module poodinis.registration;
import poodinis.container; import poodinis.container : DependencyContainer;
import poodinis.factory; import poodinis.factory : InstanceFactory, InstanceEventHandler, InstanceCreationException, InstanceFactoryParameters, CreatesSingleton;
class Registration { class Registration {
private TypeInfo _registeredType = null; private TypeInfo _registeredType = null;

View file

@ -11,9 +11,9 @@
*/ */
module poodinis.valueinjection; module poodinis.valueinjection;
import std.exception; import poodinis.polyfill : basicExceptionCtors;
import std.string;
import poodinis.polyfill; import std.string : format;
/** /**
* Thrown when something goes wrong during value injection. * Thrown when something goes wrong during value injection.