I'm writing an app in python and would like to offer user a plugin framework, which allow user to write plugins (as seperate .py files (module)) listen to events.
Basicially this:
# a seperate module
@listen("eventname")
async def listener():
...
Now however I'm confused which way I should use to collect listeners.
listeners = PluginListeners()
@listeners.add("eventname")
async def listener():
...
This allows user write less code, but user'll have trouble writing listener in class.
async def listener():
...
@inject
async def configure_plugin(plugin_manager = Inject[PluginManager]):
plugin_manager.register("eventname", listener)
This way user can write arbitrary listeners, but my app'll have trouble record the plugin which registered the listener.
What should I choose now?