ServiceInfo

Describes a service.

This struct shouldn't be created directly, you must use one of the static construction functions.

For example, if you wanted the service to be a singleton, you could do asSingleton!(IBaseType, ImplementationType).

Members

Aliases

FactoryFunc
alias FactoryFunc = Object delegate(ref ServiceScope)
Undocumented in source.
FactoryFuncFor
alias FactoryFuncFor(T) = T delegate(ref ServiceScope)
Undocumented in source.

Enums

isValidBaseType
eponymoustemplate isValidBaseType(T)
Undocumented in source.
isValidImplType
eponymoustemplate isValidImplType(BaseT, T)
Undocumented in source.
isValidImplType
eponymoustemplate isValidImplType(T)
Undocumented in source.

Functions

opEquals
bool opEquals(ServiceInfo rhs)

This is mostly for unit tests.

toHash
size_t toHash()

So we can use this struct as an AA key more easily

Mixins

__anonymous
mixin ServiceLifetimeFunctions!(ServiceLifetime.Singleton)
Undocumented in source.
__anonymous
mixin ServiceLifetimeFunctions!(ServiceLifetime.Transient)
Undocumented in source.
__anonymous
mixin ServiceLifetimeFunctions!(ServiceLifetime.Scoped)
Undocumented in source.

Static functions

asRuntime
ServiceInfo asRuntime(TypeInfo baseType, TypeInfo implType, FactoryFunc factory, TypeInfo[] dependencies)

An internal function, public due to necessity, however will be used to explain the asXXXRuntime functions.

asTemplated
ServiceInfo asTemplated(FactoryFuncFor!ImplType factory)

An internal function, public due to necessity, however will be used to explain the asXXX functions.

Examples

static interface I {}
static class C : I {}

Object dummyFactory(ref ServiceScope){ return null; }

// Testing: All 3 aliases can be found, 1 alias per lifetime, which also tests that all lifetimes are handled properly.
assert(
    ServiceInfo.asSingletonRuntime(typeid(I), typeid(C), &dummyFactory)
    ==
    ServiceInfo(typeid(I), typeid(C), &dummyFactory, ServiceLifetime.Singleton, null)
);

assert(
    ServiceInfo.asTransient!(I, C)((ref provider) => new C())
    ==
    ServiceInfo(typeid(I), typeid(C), &dummyFactory, ServiceLifetime.Transient, null) // NOTE: Factory func is ignored in opEquals, so `dummyFactory` here is fine.
);

assert(
    ServiceInfo.asScoped!C()
    ==
    ServiceInfo(typeid(C), typeid(C), &dummyFactory, ServiceLifetime.Scoped, null)
);

// opEquals and opHash don't care about dependencies (technically I think they should, but meh), so we have to test directly.
static class WithDeps
{
    this(C c, I i, int a){}
}

auto deps = ServiceInfo.asScoped!WithDeps()._dependencies;
assert(deps.length == 2);
assert(deps[0] is typeid(C));
assert(deps[1] is typeid(I));

Meta