Configure multiple Grafts

When to use this

One application consumes several Grafts — some in-memory, some remote — without a monolithic config file.

Deep reference: Runtime call execution.

Prerequisites


Rules

  1. Each Graft resolves independently
  2. Per-Graft config always overrides global config
  3. Precedence within same Graft name: env > file > code > default
  4. Global config has no Graft name — it defines shared baseline (e.g. default remote host)

Multiple Grafts in one application — independent in-memory and remote configuration


Global configuration

Applies to all Grafts unless overridden.

File: graftcode-config.json

{
  "host": "tcp://shared-gateway:8990"
}

All Grafts call through shared-gateway unless they define their own config.


Per-Graft configuration

Use the Graft's exact package name as the config entry name.

File: @graft-nuget-Orders-config.json

{
  "host": "tcp://order-service:8990"
}

File: @graft-nuget-Catalog-config.json

{
  "host": "tcp://catalog-service:8990"
}

Or in code:

import { GraftConfig as OrdersConfig } from "@graft/nuget-Orders";
import { GraftConfig as CatalogConfig } from "@graft/nuget-Catalog";

OrdersConfig.host = "tcp://orders:8990";
CatalogConfig.host = "tcp://catalog:8990";

Mixed execution example

GraftConfigExecution
@graft/nuget-SharedLib(none)In-memory (monolith module)
@graft/nuget-Billingtcp://billing:8990Remote microservice
@graft/nuget-Legacytcp://legacy:8990Remote legacy host
// SharedLib: no host → in-memory
import { Helper } from "@graft/nuget-SharedLib";

// Billing: per-graft config file sets tcp://billing:8990
import { BillingService } from "@graft/nuget-Billing";

Environment variables

Runtime-specific and global env vars beat config files. Use in CI/CD for production hosts without rebuilding.

See Environment variables and Config file formats.


Verify it works

  • In-memory Graft works with remote GG stopped (for that module)
  • Remote Grafts fail when their target GG is down
  • Changing one Graft's config does not affect others

Common mistakes

MistakeFix
Global host forces all remoteAdd per-Graft override files
Wrong config file nameMatch exact graft package name
Expecting one host for allUse per-Graft files or separate GraftConfig imports

See also