Use getOverloads in registerContextComponents (fix #43)

This commit is contained in:
Mike Bierlee 2023-03-07 01:18:11 +03:00
parent b8caa00be1
commit 6d1bf44d28

View file

@ -71,16 +71,17 @@ public void registerContext(Context : ApplicationContext)(shared(DependencyConta
public void registerContextComponents(ApplicationContextType : ApplicationContext)( public void registerContextComponents(ApplicationContextType : ApplicationContext)(
ApplicationContextType context, shared(DependencyContainer) container) ApplicationContextType context, shared(DependencyContainer) container)
{ {
foreach (member; __traits(allMembers, ApplicationContextType)) foreach (memberName; __traits(allMembers, ApplicationContextType))
{ {
static if (__traits(getProtection, __traits(getMember, context, foreach (overload; __traits(getOverloads, context, memberName))
member)) == "public" && hasUDA!(__traits(getMember, context, member), Component))
{ {
auto factoryMethod = &__traits(getMember, context, member); static if (__traits(getProtection, overload) == "public" && hasUDA!(overload, Component))
{
auto factoryMethod = &__traits(getMember, context, memberName);
Registration registration = null; Registration registration = null;
auto createsSingleton = CreatesSingleton.yes; auto createsSingleton = CreatesSingleton.yes;
foreach (attribute; __traits(getAttributes, __traits(getMember, context, member))) foreach (attribute; __traits(getAttributes, overload))
{ {
static if (is(attribute == RegisterByType!T, T)) static if (is(attribute == RegisterByType!T, T))
{ {
@ -99,7 +100,12 @@ public void registerContextComponents(ApplicationContextType : ApplicationContex
} }
registration.instanceFactory.factoryParameters = InstanceFactoryParameters( registration.instanceFactory.factoryParameters = InstanceFactoryParameters(
registration.instanceType, createsSingleton, null, factoryMethod); registration.instanceType,
createsSingleton,
null,
factoryMethod
);
}
} }
} }
} }