Cell
#
1. OverviewFrom architecture point of view, cell has different meaning from a class decorated by @cell
decorator. This class is just a driver, you will learn more about driver in virtual network section.
Cell can represent for many things. It can be a domain, a bounded context, an aggregate root, a service(in term of microservices),... Overall, a cell look like a class(~object) - it can have data and behaviour.
#
2. Cell decoratorA valid cell's driver must be decorated by @Cell
decorator. @Cell
options includes:
#
2.1. ProvidersProviders allow you to define how to create dependencies that can be injected into services of current cell.
Example 1: add providers into cell manually.
import { Cell } from "@cellular/net";
@Cell({ providers: [ { token: 'foo', useValue: 'bar' }, { token: 'key', useFunc: () => 'value' }, ],})export class User { }
Example 2: scanning folder for providers automatically.
note
This function only work for class decorated by @Injectable
decorator.
import { Cell } from "@cellular/net";
@Cell({ // scanning './data' folder for providers providers: ['./data'],})export class User { }
Example 3: using both manual and automatic method.
import { Cell } from "@cellular/net";
@Cell({ providers: [ { token: 'foo', useValue: 'bar' }, './data', // scanning './data' folder for providers ],})export class User { }
#
2.2. Importsimports
allow you to add modules into current cell.
Example:
import { CommonModule } from '$share/modules/common';
@Cell({ imports: [CommonModule],})export class User { }
#
2.3. Listenlisten
allow you to register services into a cell. There are 2 way to register services into cell:
Simple, add services manually:
import { GetInfo } from './services/get-info';import { EditInfo } from './services/edit-info';
@Cell({ listen: { GetInfo, 'EditInfoWithCustomName': EditInfo, },})export class User { }
Or, automatically scanning folder for services:
note
With this method, service class name will be used as a service name for sending request later.
@Cell({ listen: './services',})export class User { }