February 2019
Beginner
694 pages
18h 4m
English
As an alternative to the enum implementation, we could also use special purpose classes. This is best illustrated by looking at a code sample, as follows:
interface ISystemSettings { }
class IISystemSettings { }
interface IMailService { }
class IIMailService { }
class ServiceLocatorGeneric {
public static register<T>(
interfaceName: {new(): T;}, instance: any) {}
public static resolve<T>(
interfaceName: {new() : T}) {}
}
ServiceLocatorGeneric.register(IISystemSettings, {});
ServiceLocatorGeneric.resolve(IISystemSettings);
Here, we start with an interface named ISystemSettings, which is the interface that we wish to use with our service locator. We then define a class named IISystemSettings that has no functions or properties, ...
Read now
Unlock full access