How to do pluggable module extensions?

Topics: General, Writing modules
Jan 21, 2015 at 9:26 PM
Hello, I have created Currency content type which has record for Exchange Rate. I'd like to be able to update this using scheduled tasks, that should be pretty straightforward. However since implementation for provider differs from site to site (as everyone needs different exchange rate provider), I need to utilize many different implementations (which will not be part of original module distribution).

How should I approach this? My idea is to make interface like IExchangeRateProvider so they can be features enabled through Modules. But how do I ensure admin doesn't enable several of them? Also how would I instruct my main module to utilize them (since it won't have specific reference)? Providers shouldn't have scheduling logic, just return list of rates it parsed from somewhere to the main module.

Maybe somebody already did module that does something similar to this? Thanks in advance.
Developer
Jan 24, 2015 at 1:51 AM
What you describe would be the most straightforward way to do this. But you can't prevent an admin to enable multiple implementations (then one will win). Now if there can be only one exchange logic be present due to business constraints, as you explained, then I don't think this can be made much better.

You can of course put the IExchangeRateProviders into different modules and only deploy the one needed for the client.

Otherwise if you can determine from the site which one would be needed (like from the site name, or site settings) you could make providers register themselves using such arbitrary decision logic.