From 9c749c0cb62a736cea4c5f43549e7d1a86d2dc4a Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Thu, 11 Dec 2014 01:40:40 +0100 Subject: [PATCH] Check type at compile-time --- source/poodinis/autowire.d | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index b8dc35b..f31541a 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -30,16 +30,18 @@ public void autowire(Type)(DependencyContainer container, Type instance) { foreach (member ; __traits(allMembers, Type)) { static if(__traits(compiles, __traits( getMember, Type, member )) && __traits(compiles, __traits(getAttributes, __traits(getMember, Type, member )))) { foreach(attribute; __traits(getAttributes, __traits(getMember, Type, member))) { - if (is(attribute : Autowire) && __traits(getMember, instance, member) is null){ - alias TypeTuple!(__traits(getMember, instance, member)) memberReference; - auto autowirableInstance = container.resolve!(typeof(memberReference)); - debug { - auto autowirableType = typeid(typeof(memberReference[0])); - auto autowireableAddress = &autowirableInstance; - writeln(format("DEBUG: Autowire instance [%s@%s] to [%s@%s].%s", autowirableType, autowireableAddress, memberType, instanceAddress, member)); + static if (is(attribute : Autowire)) { + if (__traits(getMember, instance, member) is null) { + alias TypeTuple!(__traits(getMember, instance, member)) memberReference; + auto autowirableInstance = container.resolve!(typeof(memberReference)); + debug { + auto autowirableType = typeid(typeof(memberReference[0])); + auto autowireableAddress = &autowirableInstance; + writeln(format("DEBUG: Autowire instance [%s@%s] to [%s@%s].%s", autowirableType, autowireableAddress, memberType, instanceAddress, member)); + } + + __traits(getMember, instance, member) = autowirableInstance; } - - __traits(getMember, instance, member) = autowirableInstance; } } }