Skip to main content

GenzyContainer

What GenzyContainer is

GenzyContainer holds a set of related service classes. It is responsible for handling their lifecycle and managing their dependencies.

GenzyContainer can hold Local or Remote services.

Local Services

Local services are ones that are running in the same process as GenzyContainer.

const { GenzyContainer } = require("@genzy/client"); // or "@genzy/api"

class UserService {
async getAll() {
return [];
}
}

class AccountService {
constructor({ userService }) {
this.userService = userService;
}

async getAll() {
const accounts = [];
const users = await this.userService.getAll();
return users.map(user => ({
...user,
account: accounts.find(acc => acc.id === user.accountId)
}));
}
}

// Creating the GenzyContainer
const container = new GenzyContainer().addLocalServices(UserService, AccountService);

// Getting the services out of the GenzyContainer.
const { accountService } = nimble.getAllServices();

Remote Services

Remote services are, as the name suggests, running in a different process, or on a different server. Methods of a remote service, that is in a GenzyContainer do not require any implementation code, but do require the URL of the server they are running on.

const { GenzyContainer } = require("@genzy/client"); // or "@genzy/api"

class UserService {
async getAll() {}
}

class AccountService {
async getAll() {}
}

// Creating the GenzyContainer
const container = new GenzyContainer()
.addRemoteServices("http://localhost:3000", UserService, AccountService);

// Getting the services out of the GenzyContainer.
const { accountService } = nimble.getAllServices();

GenzyContainer implicitly creates a Proxy for each service that gets the results of method calls over HTTP.