feat(party): give every application its own plugin instances (quick-261118-lbt)

- Register keeps a pristine shallow copy of each pointer-to-struct plugin;
  every Activate hands its application a fresh copy, so a second
  application no longer rebinds the first one's plugins
- value plugins and pointers to non-struct types are used as is
- party.RegisterFactory for plugins whose init builds maps or pointers
- activate() and its tests are unchanged
- README and plugin/lifecycle docs describe the per-application rule
This commit is contained in:
Jakub Zych
2026-11-18 15:37:06 +01:00
parent 4d3b1e9f62
commit ea1befdd6c
5 changed files with 347 additions and 16 deletions

View File

@@ -25,6 +25,8 @@ A plugin is a Go type that implements `party.Plugin`. Its package registers it f
| `party.Plugin.Register` | Runs before any plugin boots. Publish services on the container here. |
| `party.Plugin.Boot` | Runs after every plugin registered. Listen to events and use other plugins' services here. |
Every application gets its own instance of the plugin. `party.Activate` hands each application a fresh shallow copy of the struct passed to `party.Register`, so a plugin keeps per-application state (the app it stored in Register, clients built from its config) on its struct, never in package variables. Fields set in the registered literal carry over to every copy; a map or pointer set there is shared by all applications. A plugin whose `init` builds such maps or pointers registers a constructor with `party.RegisterFactory` instead, which `party.Activate` calls once per application. A plugin that is not a pointer to a struct is used as is.
Here is a complete plugin that also declares a backend permission:
```go src=modules/party/example_plugin_test.go