Waher.Runtime.Inventory.IModule. Runtime inventory finds concrete implementations, creates them, calls Start(), and later calls Stop() during shutdown.
IConfigurableModule when the assembly also contributes setup pages:
Ownership rule
Every resource acquired or registered inStart() must have one clear owner and a matching release in Stop(). Store the exact instance/delegate; many unregister operations require identity equality.
HttpResource or a controller router.
Start safely
- Validate configuration without logging secrets.
- Create dependencies that do not publish work.
- Register routes, stanza handlers, event sinks, and runtime services.
- Start background loops last.
- If any step fails, unwind already-created resources before rethrowing.
Start(). Keep a cancellation token source and task, surface unexpected termination to the event log, and await the task during Stop().
Stop safely
- Stop accepting new work or unregister ingress.
- Cancel background loops.
- Await in-flight tasks with a bounded policy.
- Flush durable state and queues.
- Unregister handlers, routes, event sinks, and timers.
- Dispose owned dependencies.
Stop() safe after a partial start and safe if called once more. Do not dispose gateway-owned singletons such as Gateway.HttpServer or the global database provider.
Runtime inventory
Types.GetTypesImplementingInterface(...) and Types.Instantiate(...) are used throughout Neuron to discover endpoints, handlers, Script functions, MCP tools, converters, and other extensions. Consequences:
- avoid two discoverable implementations claiming the same route/name/namespace;
- make discovered types concrete and constructible according to the consuming subsystem;
- use
[Singleton]only when one shared instance is correct; - expect adding an assembly to change inventory results globally;
- test startup with the same assembly set as production.
Failure visibility
Log the module/type name and stable event ID. Throwing fromStart() should prevent a falsely healthy deployment; swallowing registration failures can leave only part of a package active.