Injector.execute

Executes a function where all of its parameters are retrieved from the given ServiceScope.

Limitations: Currently you cannot provide your own values for parameters that shouldn't be injected.

Behaviour: For parameters that are a class or interface, an attempt to retrieve them as a service from services is made. These parameters will be null if no service for them was found.

For parameters of other types, they are left as their .init value.

class Injector
static final
ReturnType!F
execute
(
F
)
if (
isSomeFunction!F
)

Parameters

services ServiceScope

The ServiceScope allowing access to any services to be injected into the function call.

func F

The function to execute.

Return Value

Type: ReturnType!F

Whatever func returns.

Examples

static class AandB
{
    int a = 1;
    int b = 3;
}

static int addAandB(AandB ab)
{
    return ab.a + ab.b;
}

auto services = new ServiceProvider([ServiceInfo.asSingleton!AandB]);

assert(Injector.execute(services.defaultScope, &addAandB) == 4);

Meta