This is mostly for unit tests.
So we can use this struct as an AA key more easily
An internal function, public due to necessity, however will be used to explain the asXXXRuntime functions.
An internal function, public due to necessity, however will be used to explain the asXXX functions.
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));
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).