Media Browser has a provider model, this is basically a chain of classes that get called in a particular order for each entity.
So for example we have:
providers = new List<IMetadataProvider>();
providers.Add(new ImageFromMediaLocationProvider());
providers.Add(new ImageByNameProvider());
providers.Add(new MovieProviderFromXml());
providers.Add(new MovieDbProvider());
providers.Add(new TVProviderFromXmlFiles());
providers.Add(new TvDbProvider());
providers.Add(new VirtualFolderProvider());
providers.Add(new FrameGrabProvider());
providers.Add(new MediaInfoProvider());
The order of the providers in the list is significant higher order providers take precedence over lower order ones.
Recently, I have tried to make this portion extensible. So a third party DLL can define its own providers that will get injected in our chain.
The problem is that once you allow for 3rd parties to inject themselves in the chain you lose a central place to define this order.
My current solution that I am a little uncomfortable with is to define a optional priority attribute with each provider and then order by the priority.
So for example I now have:
[ProviderPriority(20)]
class ImageByNameProvider{}
This allows 3rd parties to define their position in the chain.
Another solutions I thought about were before and after attribute Eg.
[Before(typeof(ImageByNameProvider))]
class ImageFromMediaLocationProvider {}
But, I am not sure if this is easier or harder to program against.
Are there any other solutions to this problem? Which solution would you go with?
Perhaps, I should just keep the list for the core providers and add the Before/After attribs for third party providers ...