Skip to content

Controller Decorator

This file defines the Controller decorator, which is used to mark classes as thread controllers in the @sodacore/core library. Thread controllers can accept and respond to messages from threads via IPC (Inter-Process Communication), using a specified namespace.


Features

  • Thread Controller Registration: Marks a class as a thread controller for IPC communication.
  • Namespace Assignment: Associates a namespace with the controller, used to route IPC messages.
  • Service Metadata: Registers the controller as a thread service for discovery and management.

Usage

typescript
import Controller from './decorator/controller';

@Controller('myNamespace')
export class MyThreadController {
	// Define methods to handle thread messages here
}
  • All methods under the controller will be prefixed with the specified namespace.
  • Messages can be sent to a thread controller using this.dispatch('namespace/method', contextData);.

API

Controller(namespace: string): ClassDecorator

  • namespace: The namespace to associate with the controller for IPC routing.
  • Returns: A class decorator that sets the appropriate metadata for thread controllers.

How It Works

  • Sets the type metadata to 'controller' for autowiring.
  • Sets the namespace metadata under the 'thread' namespace.
  • Adds 'thread' to the list of services in the controller's metadata.

Notes

  • Use this decorator on classes that should handle IPC messages from threads.
  • The namespace helps route messages to the correct controller and method.

Released under the Apache-2.0 License.