Recently was trying to work out how to allow custom resources to be specified in Dashen. I already know what data is needed/defined for a resource: a name, a MIME type, and a Stream. We can make this required data known very easily:
As all the parameters can only be set through the constructor, you are communicating that they are all required.
However when it comes to adding this
Resource into our configuration, we are met with 3 possible solutions:
Resource collection on the config
DashboardConfiguration object is only used in this one call, it implies that the contents of it only get read once.
Nothing to stop you holding on to a reference to the
Resources collection though.
AddResource method on the config
Resources are still added to the
DashboardConfiguration, but this time via a method. This hides the internal storage of resources. Second version also means we can hide the
Resource class from the public too if we want.
Also implies a level of uniqueness - could throw an exception on duplicate name being added, or rename the method to
AddUniqueResource or similar.
AddResource method on the Dashboard
Resource class is still hideable. Being able to add to the dashboard rather than the config implies that resources could be added at anytime, rather than just startup/config time.
In the end I decided to expose the
Resources as an
IEnumerable<Resource> on the
DashboardConfiguration object. I did this as I don't actually mind if the collection gets modified once the dashboard is started, and I can see some use-cases for dynamic resource resolution.