Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Latest commit

 

History

History
56 lines (40 loc) · 2.13 KB

service-container.md

File metadata and controls

56 lines (40 loc) · 2.13 KB

The service container is a way to manage dependencies and performing dependency injection. We have wrapped Inversify for our container. It is important to understand this concept as Varies core its built with the injection system.

Bindings

You should for the most part always bind in a service provider, and we have provided one for you to get started in app/providers.

Binding Interfaces to Implementations

Binding a interface to an implementation allows us to inject its implementation just based on the interface we want to use. For instance, we have a DocumentationInterface. Then we have a implementation of that interface, lets say VarieDocumentationService. Now we can resolve DocumentationService to VarieDocumentationService.

this.app.bind <
  DocumentationInterface >
  ("DocumentationService", VarieDocumentationService);

Value Binding

Within your service provider you have access to this.app which is your app instance and can bind things to it. We are able to bind and resolve with the app object.

this.app.value("$searchService", () => {
  return new SearchService(new SomeSearchClass());
});

Singleton Binding

We also can bind a singleton instance so we may only want to resolve once.

this.app.singleton("$searchService", () => {
  return new SearchService(new SomeSearchClass());
});

Resolving Dependencies

Dependency Injection documentation.

Framework Services Available

Varie registers some services that help boot the application. And are available to you to help development.