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;
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;

View file

@ -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;

View file

@ -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) {}

View file

@ -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");
}
}
}

View file

@ -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 ~ `;`;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;

View file

@ -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.