-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] 🧩 Plugins #15
Comments
I just published a new branch with the plugins subsystem here. How to create a pluginWrite a class that implements the Of course it can also accept its own set of options, typically modelled via How to use a plugin via DIRegister your plugin type in the DI container (better before registering FusionCache itself) to respond to the Of course you can also define your own custom ext method (like this one) to be a better .NET citizen. Example: [...]
services.AddSingleton<IFusionCachePlugin, MyPlugin>();
services.AddFusionCache();
[...] or with a custom ext method + custom options: [...]
services.AddMyFusionCachePlugin(options => {
options.Whatever = 42;
});
services.AddFusionCache();
[...] How to use a plugin without DIJust create an instance of your plugin and pass it to the Remember that, in case the Removing a pluginIf you need continue using a FusionCache instance but want to remove a plugin you've previously added, you can call the If instead you just want to clean things up "at the end" (and you should do it), you don't have to do anything because when the Opinions?Anything would be appreciated, thanks! |
Pinging @JoeShook because of course 😄 |
The plugins subsystem has been released with v0.1.5 🎉 |
Scenario
While playing with the implementation of the backplane (see #11) and talking about adding metrics (see #9) the need emerged to be able to add functionalities around FusionCache via external code.
In some cases a specific interface is needed because it is a core part of the system (like the already existing
IFusionCacheSerializer
), but in a lot of other cases a more generic one would probably suffice.The objective is to:
Proposal
The idea is to create a plugin subsystem where multiple plugins can be implemented using a common interface that would allow the coordination with a FusionCache instance.
As a first draft I'm thinking about something like this:
In the
Start
method a plugin implementer will receive a cache instance to then, for example, subscribe to the events they'd like (see #14) or do something else, while in theStop
they can remove the events subscriptions they've created before, to keep a system clean.A plugin will be added to a cache with a method like
IFusioCache.AddPlugin(IFusionCachePlugin plugin)
, similarly to the one for the distributed cache which would add the plugin instance to an internal list of plugins, and call itsStart
method. In the same vein, a methodIFusioCache.RemovePlugin(IFusionCachePlugin plugin)
can be called to remove a plugin (which in turn will call theStop
method on the plugin) for housekeeping purposes.Dependency Injection
In a DI scenario the method will be called automatically for all the registered services implementing the IFusionCachePlugin type, like what is already happening for the IDistributedCache type here, but with potentially multiple implementations.
The code may be something like this:
Specialized plugin types
In case specific functionalities may be needed by FusionCache, a more specialized plugin type may be created simply inheriting from the base
IFusionCachePlugin
type and adding the specific apis needed.If, for example, the metrics plugins need a special metrics-related method to be called for metrics-related things, we would have something like this:
NOTE: I'm still playing with the backplane impl, and it could very well fit into this as a "normal" plugin.
Other stuff to decide
Should there be a way to identify a plugin, apart from its clr type? Something like a
string Id { get; set; }
? It may be useful in some contexts (eg: logging).Thoughts?
Any suggestion is more than welcome.
The text was updated successfully, but these errors were encountered: