...

/

Solution: Build a Multi-Tenant Service Factory

Solution: Build a Multi-Tenant Service Factory

Use chained object lookups to resolve a service from tenant scope, falling back to the default, without conditionals.

We'll cover the following...

Solution explanation

  • Lines 1–21: We define a serviceRegistry object containing all tenant-specific and default service classes.

    • The acme tenant overrides only the Logger service with AcmeLogger.

    • The default tenant provides DefaultLogger and DefaultAuth, used whenever a tenant doesn’t override a service.

  • Lines 23–29: The createService(tenantId, serviceName) factory resolves and returns the ...