Visual Studio Code's "instantiation" system
decoration-ioc is a very simple inversion of control and dependency injection framework. Taken directly from Visual Studio Code, decoration-ioc provides robust service location and constructor injection with automatic dependency resolution.
Quickstart
First, make sure that the experimentalDecorators
TypeScript compiler option is set to true
.
Define a service interface
// Define the service. // Create a decorator used to reference the interface type.;
Note that the decorator has the same name as the interface. You'll only need to import IMyService
!
Create a concrete implementation
Register the concrete type for the service
// Create a service collection where concrete implementation types are registered.; // Declare that the MyService class is the type that is instantiated when an IMyService is needed.serviceCollection.setIMyService, new DescriptorMyService;
Creating instances
// Create an instantiation service that performs constructor injection.// It uses the service collection to resolve dependencies and create instances.; // This is a class that requires an instance of IMyService when created. // Create an instance of myDependentClass.;myDependentClass.makeMyServiceSayHello;