From 6b2a54ca5e708ad2b4cdc7893733c0bd1a4ab392 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 1 Jun 2020 08:32:29 -0700 Subject: [PATCH] chore(docs): use `@loopback/core` for imports of `@loopback/context` --- docs/site/BelongsTo-relation.md | 2 +- docs/site/Binding.md | 26 +++++++++++++++---- docs/site/Context.md | 20 +++++++++++--- docs/site/Controller-generator.md | 2 +- docs/site/Creating-components.md | 6 ++--- docs/site/Dependency-injection.md | 19 ++++++++++++-- docs/site/Express-middleware.md | 2 +- docs/site/Extending-LoopBack-4.md | 2 +- docs/site/Extension-point-and-extensions.md | 4 +-- docs/site/FAQ.md | 2 +- docs/site/File-upload-download.md | 4 +-- docs/site/Interceptor-generator.md | 4 +-- docs/site/Interceptors.md | 14 +++++----- .../site/LB3-vs-LB4-request-response-cycle.md | 2 +- docs/site/Life-cycle.md | 6 ++--- .../site/Loopback-component-authentication.md | 4 +-- docs/site/Middleware.md | 2 +- docs/site/Repositories.md | 4 +-- docs/site/Sequence.md | 4 +-- docs/site/Testing-Your-Extensions.md | 4 +-- docs/site/Testing-your-application.md | 2 +- .../decorators/Decorators_authenticate.md | 2 +- docs/site/decorators/Decorators_inject.md | 23 +++++++++++++--- docs/site/extending/rest-api.md | 4 +-- .../migration/components/project-layout.md | 2 +- docs/site/migration/models/mixins.md | 6 ++--- .../tutorials/core/3-context-in-action.md | 2 +- .../tutorials/core/4-dependency-injection.md | 4 +-- .../core/5-extension-point-extension.md | 8 +++--- .../tutorials/core/9-boot-by-convention.md | 2 +- ...soap-calculator-tutorial-add-controller.md | 2 +- 31 files changed, 124 insertions(+), 66 deletions(-) diff --git a/docs/site/BelongsTo-relation.md b/docs/site/BelongsTo-relation.md index 284e7a9e936c..917ad3daf965 100644 --- a/docs/site/BelongsTo-relation.md +++ b/docs/site/BelongsTo-relation.md @@ -238,7 +238,7 @@ The following code snippet shows how it would look like: content="/src/repositories/order.repository.ts" %} ```ts -import {Getter, inject} from '@loopback/context'; +import {Getter, inject} from '@loopback/core'; import { BelongsToAccessor, DefaultCrudRepository, diff --git a/docs/site/Binding.md b/docs/site/Binding.md index 74b6b819864f..acede6c529be 100644 --- a/docs/site/Binding.md +++ b/docs/site/Binding.md @@ -32,6 +32,7 @@ There are a few ways to create a binding: - Use `Binding` constructor: ```ts + import {Context, Binding} from '@loopback/core'; const context = new Context(); const binding = new Binding('my-key'); ctx.add(binding); @@ -40,6 +41,7 @@ There are a few ways to create a binding: - Use `Binding.bind()` ```ts + import {Context, Binding} from '@loopback/core'; const context = new Context(); const binding = Binding.bind('my-key'); ctx.add(binding); @@ -48,10 +50,24 @@ There are a few ways to create a binding: - Use `context.bind()` ```ts + import {Context, Binding} from '@loopback/core'; const context = new Context(); context.bind('my-key'); ``` + {% include note.html content="The `@loopback/core` package re-exports all + public APIs of `@loopback/context`. For consistency, we recommend the usage of + `@loopback/core` for imports in LoopBack modules and applications unless they + depend on `@loopback/context` explicitly. The two statements below are + equivalent: + + ```ts + import {inject} from '@loopback/context'; + import {inject} from '@loopback/core'; + ``` + + " %} + ## How to set up a binding? The `Binding` class provides a set of fluent APIs to create and configure a @@ -87,7 +103,7 @@ The factory function can receive extra information about the context, binding, and resolution options. ```ts -import {ValueFactory} from '@loopback/context'; +import {ValueFactory} from '@loopback/core'; // The factory function now have access extra metadata about the resolution const factory: ValueFactory = resolutionCtx => { @@ -113,7 +129,7 @@ An advanced form of value factory is a class that has a static `value` method that allows parameter injection. ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; class GreetingProvider { static value(@inject('user') user: string) { @@ -458,7 +474,7 @@ match/find bindings by tag. The search criteria can be one of the followings: filterByTag, includesTagValue, // Match tag value as an array that includes the item TagValueMatcher, - } from '@loopback/context'; + } from '@loopback/core'; // Match a binding with a named service ctx.find(filterByTag({name: ANY_TAG_VALUE, service: 'service'})); @@ -504,7 +520,7 @@ When the class is bound, these attributes are honored to create a binding. You can use `@bind` decorator to configure how to bind a class. ```ts -import {bind, BindingScope} from '@loopback/context'; +import {bind, BindingScope} from '@loopback/core'; // @bind() accepts scope and tags @bind({ @@ -538,7 +554,7 @@ export class YourController {} Then a binding can be created by inspecting the class, ```ts -import {createBindingFromClass} from '@loopback/context'; +import {createBindingFromClass} from '@loopback/core'; const ctx = new Context(); const binding = createBindingFromClass(MyService); diff --git a/docs/site/Context.md b/docs/site/Context.md index 5216621ae181..c0078be25bc7 100644 --- a/docs/site/Context.md +++ b/docs/site/Context.md @@ -37,13 +37,26 @@ can be chained using the `parent` to form a hierarchy. For example, the code below creates a chain of three contexts: `reqCtx -> serverCtx -> rootCtx`. ```ts -import {Context} from '@loopback/context'; +import {Context} from '@loopback/core'; const rootCtx = new Context('root-ctx'); // No parent const serverCtx = new Context(rootCtx, 'server-ctx'); // rootCtx as the parent const reqCtx = new Context(serverCtx); // No explicit name, a UUID will be generated ``` +{% include note.html content="The `@loopback/core` package re-exports all public +APIs of `@loopback/context`. For consistency, we recommend the usage of +`@loopback/core` for imports in LoopBack modules and applications unless they +depend on `@loopback/context` explicitly. The two statements below are +equivalent: + +```ts +import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; +``` + +" %} + LoopBack's context system allows an unlimited amount of Context instances, each of which may have a parent Context. @@ -180,8 +193,7 @@ However, when using classes, LoopBack provides a better way to get at stuff in the context via the `@inject` decorator: ```ts -import {inject} from '@loopback/context'; -import {Application} from '@loopback/core'; +import {inject, Application} from '@loopback/core'; const app = new Application(); app.bind('defaultName').to('John'); @@ -489,7 +501,7 @@ be used to watch a list of bindings matching certain criteria depicted by a matched bindings. ```ts -import {Context, ContextView} from '@loopback/context'; +import {Context, ContextView} from '@loopback/core'; // Set up a context chain const appCtx = new Context('app'); diff --git a/docs/site/Controller-generator.md b/docs/site/Controller-generator.md index 27ea530c1fa5..04a1c76f3680 100644 --- a/docs/site/Controller-generator.md +++ b/docs/site/Controller-generator.md @@ -51,7 +51,7 @@ based on the given name: ```ts // Uncomment these imports to begin using these cool features! -// import {inject} from '@loopback/context'; +// import {inject} from '@loopback/core'; export class FooController { constructor() {} diff --git a/docs/site/Creating-components.md b/docs/site/Creating-components.md index be5563996df5..3ddaa1502c5c 100644 --- a/docs/site/Creating-components.md +++ b/docs/site/Creating-components.md @@ -90,7 +90,7 @@ function called by [Context](Context.md) when another entity requests a value to be injected. ```ts -import {Provider} from '@loopback/context'; +import {Provider} from '@loopback/core'; export class MyValueProvider implements Provider { value() { @@ -168,7 +168,7 @@ the list of keys reserved for the framework use. Provider's `value()` method can be asynchronous too: ```ts -import {Provider} from '@loopback/context'; +import {Provider} from '@loopback/core'; const request = require('request-promise-native'); const weatherUrl = 'http://samples.openweathermap.org/data/2.5/weather?appid=b1b15e88fa797225412429c1c50c122a1'; @@ -192,7 +192,7 @@ dependencies annotated with `@inject` keyword, so that LoopBack runtime can resolve them automatically. ```ts -import {Provider} from '@loopback/context'; +import {Provider} from '@loopback/core'; import {Request, RestBindings} from '@loopback/rest'; import {v4 as uuid} from 'uuid'; diff --git a/docs/site/Dependency-injection.md b/docs/site/Dependency-injection.md index 9c2cb5918d77..ba5807d722bb 100644 --- a/docs/site/Dependency-injection.md +++ b/docs/site/Dependency-injection.md @@ -22,6 +22,8 @@ the caller specify which strategy to use. The implementation of the `authenticate` action is shown below. ```ts +import {inject, Provider} from '@loopback/core'; + export class AuthenticateActionProvider implements Provider { constructor( // The provider is instantiated for Sequence constructor, @@ -73,6 +75,19 @@ export class AuthenticateActionProvider implements Provider { } ``` +{% include note.html content="The `@loopback/core` package re-exports all public +APIs of `@loopback/context`. For consistency, we recommend the usage of +`@loopback/core` for imports in LoopBack modules and applications unless they +depend on `@loopback/context` explicitly. The two statements below are +equivalent: + +```ts +import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; +``` + +" %} + Dependency Injection makes the code easier to extend and customize, because the dependencies can be easily rewired by the application developer. It makes the code easier to test in isolation (in a pure unit test), because the test can @@ -296,7 +311,7 @@ problem. Consider the following example: ```ts -import {Context, inject} from '@loopback/context'; +import {Context, inject} from '@loopback/core'; interface Developer { // Each developer belongs to a team @@ -363,7 +378,7 @@ Let's take a look at the following example: The corresponding code is: ```ts -import {inject, Context, BindingScope} from '@loopback/context'; +import {inject, Context, BindingScope} from '@loopback/core'; import {RestBindings} from '@loopback/rest'; interface Logger() { diff --git a/docs/site/Express-middleware.md b/docs/site/Express-middleware.md index cc2e99b411e9..e679da86ac3b 100644 --- a/docs/site/Express-middleware.md +++ b/docs/site/Express-middleware.md @@ -220,7 +220,7 @@ Alternatively, we can create a subclass of `ExpressMiddlewareInterceptorProvider`. ```ts -import {config} from '@loopback/context'; +import {config} from '@loopback/core'; import { ExpressMiddlewareInterceptorProvider, createMiddlewareInterceptorBinding, diff --git a/docs/site/Extending-LoopBack-4.md b/docs/site/Extending-LoopBack-4.md index 4b6166d2c12f..df1c9fc379eb 100644 --- a/docs/site/Extending-LoopBack-4.md +++ b/docs/site/Extending-LoopBack-4.md @@ -46,7 +46,7 @@ that the service provider can be injected into the consumer class. The code snippet below shows the usage of `@inject` for dependency injection. ```ts -import {inject, Context} from '@loopback/context'; +import {inject, Context} from '@loopback/core'; /** * A UserController implementation that depends on UserRepository and PasswordHasher diff --git a/docs/site/Extension-point-and-extensions.md b/docs/site/Extension-point-and-extensions.md index ba2e4ec6bfdf..024ebef3a30d 100644 --- a/docs/site/Extension-point-and-extensions.md +++ b/docs/site/Extension-point-and-extensions.md @@ -68,7 +68,7 @@ decorators and functions are provided to ensure consistency and convention. 1. Inject a getter function for extensions ```ts - import {Getter} from '@loopback/context'; + import {Getter} from '@loopback/core'; import {extensionPoint, extensions} from '@loopback/core'; @extensionPoint('greeters') @@ -81,7 +81,7 @@ decorators and functions are provided to ensure consistency and convention. 2. Inject a context view for extensions ```ts - import {ContextView} from '@loopback/context'; + import {ContextView} from '@loopback/core'; import {extensionPoint, extensions} from '@loopback/core'; @extensionPoint('greeters') diff --git a/docs/site/FAQ.md b/docs/site/FAQ.md index 7ea75f527b72..17ffafab1d41 100644 --- a/docs/site/FAQ.md +++ b/docs/site/FAQ.md @@ -135,7 +135,7 @@ headers). This can be accomplished by injecting the `Response` object into the controller: ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import {get, Response, RestBindings} from '@loopback/rest'; export class PingController { diff --git a/docs/site/File-upload-download.md b/docs/site/File-upload-download.md index 11fdd568098b..3e7076e42718 100644 --- a/docs/site/File-upload-download.md +++ b/docs/site/File-upload-download.md @@ -25,7 +25,7 @@ A few steps are involved to create an endpoint for file upload. [`FileUploadController`](https://github.com/strongloop/loopback-next/blob/master/examples/file-transfer/src/controllers/file-upload.controller.ts) ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import { post, Request, @@ -110,7 +110,7 @@ To download files from the backend, please follow the following steps. [`FileDownloadController`](https://github.com/strongloop/loopback-next/blob/master/examples/file-transfer/src/controllers/file-download.controller.ts) ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import { get, HttpErrors, diff --git a/docs/site/Interceptor-generator.md b/docs/site/Interceptor-generator.md index 9abe322e542a..c1e2798f7eb7 100644 --- a/docs/site/Interceptor-generator.md +++ b/docs/site/Interceptor-generator.md @@ -63,7 +63,7 @@ import { bind, Interceptor, Provider, -} from '@loopback/context'; +} from '@loopback/core'; /** * This class will be bound to the application as a global `Interceptor` during @@ -115,7 +115,7 @@ import { bind, Interceptor, Provider, -} from '@loopback/context'; +} from '@loopback/core'; /** * This class will be bound to the application as a global `Interceptor` during diff --git a/docs/site/Interceptors.md b/docs/site/Interceptors.md index 4c8417a68864..4702f0d593b5 100644 --- a/docs/site/Interceptors.md +++ b/docs/site/Interceptors.md @@ -34,7 +34,7 @@ Controller methods decorated with `@intercept` are invoked with applied interceptors for corresponding routes upon API requests. ```ts -import {intercept} from '@loopback/context'; +import {intercept} from '@loopback/core'; @intercept(log) // `log` is an interceptor function export class OrderController { @@ -74,7 +74,7 @@ services and would like to allow repository or service methods to be intercepted. ```ts -import {createProxyWithInterceptors} from '@loopback/context'; +import {createProxyWithInterceptors} from '@loopback/core'; const proxy = createProxyWithInterceptors(controllerInstance, ctx); const msg = await proxy.greet('John'); @@ -148,7 +148,7 @@ To explicitly invoke a method with interceptors, use `invokeMethod` from `RestServer` for controller methods. ```ts -import {Context, invokeMethod} from '@loopback/context'; +import {Context, invokeMethod} from '@loopback/core'; const ctx: Context = new Context(); @@ -336,7 +336,7 @@ Global interceptors are discovered from the `InvocationContext`. They are registered as bindings with `globalInterceptor` tag. For example, ```ts -import {asGlobalInterceptor} from '@loopback/context'; +import {asGlobalInterceptor} from '@loopback/core'; app .bind('globalInterceptors.MetricsInterceptor') @@ -747,7 +747,7 @@ Sometimes we want to apply more than one interceptors together as a whole. It can be done by `composeInterceptors`: ```ts -import {composeInterceptors} from '@loopback/context'; +import {composeInterceptors} from '@loopback/core'; const interceptor = composeInterceptors( interceptorFn1, @@ -768,7 +768,7 @@ is the base class that can be extended to create your own flavor of interceptors and chains. For example, ```ts -import {GenericInvocationChain, GenericInterceptor} from '@loopback/context'; +import {GenericInvocationChain, GenericInterceptor} from '@loopback/core'; import {RequestContext} from '@loopback/rest'; export interface RequestInterceptor @@ -795,7 +795,7 @@ await chain.invokeInterceptors(); It's also possible to pass in a final handler: ```ts -import {Next} from '@loopback/context'; +import {Next} from '@loopback/core'; const finalHandler: Next = async () => { // return ...; }; diff --git a/docs/site/LB3-vs-LB4-request-response-cycle.md b/docs/site/LB3-vs-LB4-request-response-cycle.md index ecd2f02973bf..7239504d9ebf 100644 --- a/docs/site/LB3-vs-LB4-request-response-cycle.md +++ b/docs/site/LB3-vs-LB4-request-response-cycle.md @@ -331,7 +331,7 @@ available to them via [dependency injection](./Dependency-injection.md). Example of accesssing the request and response object in a Controller: ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import {Request, Response, RestBindings, get} from '@loopback/rest'; export class ExampleController { diff --git a/docs/site/Life-cycle.md b/docs/site/Life-cycle.md index b7ee0948732b..ca3427049c6d 100644 --- a/docs/site/Life-cycle.md +++ b/docs/site/Life-cycle.md @@ -150,7 +150,7 @@ To react on life cycle events, a life cycle observer implements the `LifeCycleObserver` interface. ```ts -import {ValueOrPromise} from '@loopback/context'; +import {ValueOrPromise} from '@loopback/core'; /** * Observers to handle life cycle start/stop events @@ -236,7 +236,7 @@ The observer class can also be decorated with `@bind` to provide binding metadata. ```ts -import {bind, createBindingFromClass} from '@loopback/context'; +import {bind, createBindingFromClass} from '@loopback/core'; import {CoreTags, asLifeCycleObserver} from '@loopback/core'; @bind( @@ -257,7 +257,7 @@ app.add(createBindingFromClass(MyObserver)); Or even simpler with `@lifeCycleObserver`: ```ts -import {createBindingFromClass} from '@loopback/context'; +import {createBindingFromClass} from '@loopback/core'; import {lifeCycleObserver} from '@loopback/core'; @lifeCycleObserver('g1') diff --git a/docs/site/Loopback-component-authentication.md b/docs/site/Loopback-component-authentication.md index f5932e4a9974..7c3e0dbbaf65 100644 --- a/docs/site/Loopback-component-authentication.md +++ b/docs/site/Loopback-component-authentication.md @@ -146,7 +146,7 @@ Here is an example of the decorator using a custom authentication strategy named authentication strategy in later sections) ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import {AuthenticationBindings, authenticate} from '@loopback/authentication'; import {SecurityBindings, securityId, UserProfile} from '@loopback/security'; import {get} from '@loopback/rest'; @@ -715,7 +715,7 @@ with a value of `false` for the `/scareme` endpoint. We use the **default** option value for the `/whoami` endpoint. ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import {AuthenticationBindings, authenticate} from '@loopback/authentication'; import {UserProfile, securityId} from '@loopback/security'; import {get} from '@loopback/rest'; diff --git a/docs/site/Middleware.md b/docs/site/Middleware.md index f3c7feeddb9b..66458def9cda 100644 --- a/docs/site/Middleware.md +++ b/docs/site/Middleware.md @@ -71,7 +71,7 @@ work with the `MiddlewareContext` - a wrapper object for `request` and ```ts import {MiddlewareContext} from '@loopback/express'; -import {Next, ValueOrPromise, InvocationResult} from '@loopback/context'; +import {Next, ValueOrPromise, InvocationResult} from '@loopback/core'; (context: MiddlewareContext, next: Next) => ValueOrPromise; ``` diff --git a/docs/site/Repositories.md b/docs/site/Repositories.md index 6e8f6cdcf377..1a817ea29c8e 100644 --- a/docs/site/Repositories.md +++ b/docs/site/Repositories.md @@ -166,7 +166,7 @@ TypeScript version: import {DefaultCrudRepository, juggler} from '@loopback/repository'; import {Account, AccountRelations} from '../models'; import {DbDataSource} from '../datasources'; -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; export class AccountRepository extends DefaultCrudRepository< Account, @@ -354,7 +354,7 @@ implementation based on `loopback-datasource-juggler`. import {DefaultKeyValueRepository} from '@loopback/repository'; import {ShoppingCart} from '../models/shopping-cart.model'; import {RedisDataSource} from '../datasources/redis.datasource'; -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; export class ShoppingCartRepository extends DefaultKeyValueRepository< ShoppingCart diff --git a/docs/site/Sequence.md b/docs/site/Sequence.md index 473a692d411b..f6dc0dfbacfa 100644 --- a/docs/site/Sequence.md +++ b/docs/site/Sequence.md @@ -204,7 +204,7 @@ function upon injection. ```ts import {Send, Response} from '@loopback/rest'; -import {Provider, BoundValue, inject} from '@loopback/context'; +import {Provider, BoundValue, inject} from '@loopback/core'; import {writeResultToResponse, RestBindings, Request} from '@loopback/rest'; // Note: This is an example class; we do not provide this for you. @@ -264,7 +264,7 @@ import { } from '@loopback/repository'; import {CustomSendProvider} from './providers/custom-send.provider'; import {Formatter} from './utils'; -import {BindingScope} from '@loopback/context'; +import {BindingScope} from '@loopback/core'; export class YourApp extends RepositoryMixin(RestApplication) { constructor() { diff --git a/docs/site/Testing-Your-Extensions.md b/docs/site/Testing-Your-Extensions.md index c779eabd2687..beebf008f491 100644 --- a/docs/site/Testing-Your-Extensions.md +++ b/docs/site/Testing-Your-Extensions.md @@ -183,7 +183,7 @@ using a test double for any constructor arguments. {% include code-caption.html content="src/providers/random-number.provider.ts" %} ```ts -import {Provider} from '@loopback/context'; +import {Provider} from '@loopback/core'; export class RandomNumberProvider implements Provider { value() { @@ -233,7 +233,7 @@ class. Following is an example for an integration test for a Mixin: {% include code-caption.html content="src/mixins/time.mixin.ts" %} ```ts -import {Constructor} from '@loopback/context'; +import {Constructor} from '@loopback/core'; export function TimeMixin>(superClass: T) { return class extends superClass { constructor(...args: any[]) { diff --git a/docs/site/Testing-your-application.md b/docs/site/Testing-your-application.md index 80a0e8b663c1..29b683711fc7 100644 --- a/docs/site/Testing-your-application.md +++ b/docs/site/Testing-your-application.md @@ -144,7 +144,7 @@ belongs to Category, include it in the repository call, for example: {% include code-caption.html content="src/__tests__/helpers/database.helpers.ts" %} ```ts -import {Getter} from '@loopback/context'; +import {Getter} from '@loopback/core'; import {ProductRepository, CategoryRepository} from '../../repositories'; import {testdb} from '../fixtures/datasources/testdb.datasource'; diff --git a/docs/site/decorators/Decorators_authenticate.md b/docs/site/decorators/Decorators_authenticate.md index dd8da1120e19..af5089488297 100644 --- a/docs/site/decorators/Decorators_authenticate.md +++ b/docs/site/decorators/Decorators_authenticate.md @@ -20,7 +20,7 @@ Here's an example using 'BasicStrategy': to authenticate user in function {% include code-caption.html content="src/controllers/who-am-i.controller.ts" %} ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import {securityId, SecurityBindings, UserProfile} from '@loopback/security'; import {authenticate} from '@loopback/authentication'; import {get} from '@loopback/rest'; diff --git a/docs/site/decorators/Decorators_inject.md b/docs/site/decorators/Decorators_inject.md index 525e7420fd3d..4594a367f69f 100644 --- a/docs/site/decorators/Decorators_inject.md +++ b/docs/site/decorators/Decorators_inject.md @@ -55,7 +55,7 @@ WidgetController: {% include code-caption.html content="src/controllers/widget.controller.ts" %} ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; export class WidgetController { // injection for property @@ -75,6 +75,8 @@ array of values can be injected. If the target type is not `Array`, an error will be thrown. ```ts +import {inject} from '@loopback/core'; + class MyControllerWithValues { constructor( @inject(binding => binding.tagNames.includes('foo')) @@ -87,6 +89,8 @@ To sort matched bindings found by the binding filter function, `@inject` honors `bindingComparator` in `metadata`: ```ts +import {inject} from '@loopback/core'; + class MyControllerWithValues { constructor( @inject(binding => binding.tagNames.includes('foo'), { @@ -100,6 +104,19 @@ class MyControllerWithValues { } ``` +{% include note.html content="The `@loopback/core` package re-exports all public +APIs of `@loopback/context`. For consistency, we recommend the usage of +`@loopback/core` for imports in LoopBack modules and applications unless they +depend on `@loopback/context` explicitly. The two statements below are +equivalent: + +```ts +import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; +``` + +" %} + A few variants of `@inject` are provided to declare special forms of dependencies. @@ -111,7 +128,7 @@ value of the key. Syntax: `@inject.getter(bindingSelector: BindingSelector)`. ```ts -import {inject, Getter} from '@loopback/context'; +import {inject, Getter} from '@loopback/core'; import {UserProfile} from '@loopback/authentication'; import {get} from '@loopback/rest'; @@ -276,7 +293,7 @@ console.log(store.locations); // ['San Francisco', 'San Jose'] a filter function. ```ts -import {inject} from '@loopback/context'; +import {inject} from '@loopback/core'; import {DataSource} from '@loopback/repository'; export class DataSourceTracker { diff --git a/docs/site/extending/rest-api.md b/docs/site/extending/rest-api.md index 3d92b2b46f79..41d325501700 100644 --- a/docs/site/extending/rest-api.md +++ b/docs/site/extending/rest-api.md @@ -53,7 +53,7 @@ Example showing a component exporting a `/ping` endpoint at a configurable base path: ```ts -import {config} from '@loopback/context'; +import {config} from '@loopback/core'; import {Component} from '@loopback/core'; import {RestApplication} from '@loopback/rest'; import {MyComponentBindings} from './my-component.keys.ts'; @@ -99,7 +99,7 @@ The example below shows a component that always contributed a `ping` endpoint and sometimes contributes a `stats` endpoint, depending on the configuration. ```ts -import {bind, config, ContextTags} from '@loopback/context'; +import {bind, config, ContextTags} from '@loopback/core'; import {MyComponentBindings} from './my-component.keys.ts'; import {PingController, StatsController} from './controllers'; diff --git a/docs/site/migration/components/project-layout.md b/docs/site/migration/components/project-layout.md index 3480982a3058..8a6d638219fa 100644 --- a/docs/site/migration/components/project-layout.md +++ b/docs/site/migration/components/project-layout.md @@ -57,7 +57,7 @@ The component class is usually implemented inside ```ts import {Application, Component, CoreBindings} from '@loopback/core'; -import {bind, config, ContextTags, inject} from '@loopback/context'; +import {bind, config, ContextTags, inject} from '@loopback/core'; import {MetricsBindings} from './keys'; import {DEFAULT_METRICS_OPTIONS, MetricsOptions} from './types'; diff --git a/docs/site/migration/models/mixins.md b/docs/site/migration/models/mixins.md index a5e50d57182f..f486b53553f0 100644 --- a/docs/site/migration/models/mixins.md +++ b/docs/site/migration/models/mixins.md @@ -160,7 +160,7 @@ This mixin class factory function `AddCategoryPropertyMixin` in {% include code-caption.html content="src/mixins/category-property-mixin.ts" %} ```ts -import {Constructor} from '@loopback/context'; +import {Constructor} from '@loopback/core'; import {property, Model} from '@loopback/repository'; /** @@ -432,7 +432,7 @@ method to any repository. {% include code-caption.html content="src/mixins/find-by-title-repository-mixin.ts" %} ```ts -import {Constructor} from '@loopback/context'; +import {Constructor} from '@loopback/core'; import {Model, CrudRepository, Where} from '@loopback/repository'; import {FindByTitle} from './find-by-title-interface'; @@ -523,7 +523,7 @@ method to any controller. {% include code-caption.html content="src/mixins/src/mixins/find-by-title-controller-mixin.ts" %} ```ts -import {Constructor} from '@loopback/context'; +import {Constructor} from '@loopback/core'; import {Model} from '@loopback/repository'; import {FindByTitle} from './find-by-title-interface'; import {param, get, getModelSchemaRef} from '@loopback/rest'; diff --git a/docs/site/tutorials/core/3-context-in-action.md b/docs/site/tutorials/core/3-context-in-action.md index 01ee37b2e4a0..e6e67d82439c 100644 --- a/docs/site/tutorials/core/3-context-in-action.md +++ b/docs/site/tutorials/core/3-context-in-action.md @@ -34,7 +34,7 @@ To register artifacts, we first create an instance of `Context` and use `bind` to add artifacts to the registry as bindings. ```ts -import {Context} from '@loopback/context'; +import {Context} from '@loopback/core'; import {GreetingController} from './controllers'; import {CACHING_SERVICE, GREETING_SERVICE} from './keys'; import {CachingService} from './caching-service'; diff --git a/docs/site/tutorials/core/4-dependency-injection.md b/docs/site/tutorials/core/4-dependency-injection.md index c7d825876ead..890bfac17d4d 100644 --- a/docs/site/tutorials/core/4-dependency-injection.md +++ b/docs/site/tutorials/core/4-dependency-injection.md @@ -33,7 +33,7 @@ locating the dependent artifacts. For example: 2. Use `ServiceLocator` pattern ```ts - import {Context} from '@loopback/context'; + import {Context} from '@loopback/core'; import {EnglishGreeter, ChineseGreeter} from './greeters'; export class GreetingService { private chineseGreeter: ChineseGreeter; @@ -58,7 +58,7 @@ locating the dependent artifacts. For example: This technique is being used commonly within the LoopBack framework. ```ts - import {inject} from '@loopback/context'; + import {inject} from '@loopback/core'; import {LifeCycleObserver} from '@loopback/core'; import {CachingService} from '../caching-service'; import {CACHING_SERVICE} from '../keys'; diff --git a/docs/site/tutorials/core/5-extension-point-extension.md b/docs/site/tutorials/core/5-extension-point-extension.md index 452151764bcc..17e8f45f6254 100644 --- a/docs/site/tutorials/core/5-extension-point-extension.md +++ b/docs/site/tutorials/core/5-extension-point-extension.md @@ -49,8 +49,7 @@ context. In our case, we mark `GreetingService` as the extension point that has access to a list of greeters which are defined as extensions. ```ts -import {Getter} from '@loopback/context'; -import {extensionFilter, CoreTags} from '@loopback/core'; +import {extensionFilter, CoreTags, Getter} from '@loopback/core'; /** * An extension point for greeters that can greet in different languages */ @@ -164,7 +163,7 @@ knowing much about one another. ```ts import {Greeter, asGreeter} from '../types'; -import {bind, inject} from '@loopback/context'; +import {bind, inject} from '@loopback/core'; /** * Options for the Chinese greeter */ @@ -229,8 +228,7 @@ app The process can be automated with a component: ```ts -import {createBindingFromClass} from '@loopback/context'; -import {Component} from '@loopback/core'; +import {createBindingFromClass, Component} from '@loopback/core'; import {GreetingService} from './greeting-service'; import {GREETING_SERVICE} from './keys'; /** diff --git a/docs/site/tutorials/core/9-boot-by-convention.md b/docs/site/tutorials/core/9-boot-by-convention.md index 8251d76af6b6..a7549984d11f 100644 --- a/docs/site/tutorials/core/9-boot-by-convention.md +++ b/docs/site/tutorials/core/9-boot-by-convention.md @@ -13,7 +13,7 @@ be achieved by calling `Context` APIs or helper methods on the application object: ```ts -import {createBindingFromClass, BindingScope} from '@loopback/context'; +import {createBindingFromClass, BindingScope} from '@loopback/core'; import {CACHING_SERVICE} from './keys'; import {CachingService} from './caching-service'; import {GreetingController} from './controllers'; diff --git a/docs/site/tutorials/soap-calculator/soap-calculator-tutorial-add-controller.md b/docs/site/tutorials/soap-calculator/soap-calculator-tutorial-add-controller.md index ca9d910e630d..4315f382089f 100644 --- a/docs/site/tutorials/soap-calculator/soap-calculator-tutorial-add-controller.md +++ b/docs/site/tutorials/soap-calculator/soap-calculator-tutorial-add-controller.md @@ -42,7 +42,7 @@ this point. ```ts // Uncomment these imports to begin using these cool features! -// import {inject} from '@loopback/context'; +// import {inject} from '@loopback/core'; export class CalculatorController { constructor() {}