General
As a software starts to get splitted into decoupled modules you will get to the point the software needs to decide with module to use within a special case. If we want to select a module to display a preview of a given file, we might have a hand full of special modules to ask. As antony cannot known the caracteristics of the module, each one has the same permission to be used. On a closer look there might be a modules which shows a pdf file. Another module is specialized on the display of an excel sheet. The third one provides a spevial viewer for invoices of a special company.
antony wants to support all these cases, but therefore we need a mechanism to select them. The difficult aspect is the fact, the that the decision heavily depends on the context. At this point the IModuleSelector
comes into stage.
Definition
The IModuleSelector
is a generic interface with only a single function getPriority
. As you can see, it returns an AntonyPriority
depends on some selectorParameter
This parameter depends on the current context. In the example above you will get some informations about the file to display. This might be the fileName, the MimeType and perhaps the first bytes of it.
public interface IModuleSelector<in T> { AntonyPriority GetPriority(T selectorParameter); }
On the information given by the selectorParameter
the module needs to decide if it is able to display the file or not. The answer is encoded into an AntonyPriority
enumerable. This is defined as follows
public enum AntonyPriority : byte { None = 0, Buildin = 1, Generic = 2, Specific = 3, Explicit = 4 }
Priority | Description | Example |
---|---|---|
None | You can return this value if you do not want to be selected by antony | |
Buildin | You might not return this value. BuildIn is used by the implementations antony provides by house | |
Generic | This one can be used if you want to provide some generic logic. | For the file-previewer you might simply use a browser (and its plugins) to provide a wide range of preview possibilities. As you might guess: This is not very special and is limited on a technical level. |
Specific | This value can be used if you provide a specific handle for a functionality. | In the example of the file preview we might provide a special module to display a pdf file with the adobe reader. In case of the pdf file the specific module is used. For an image, the generic brower module is adequate |
Explicit | This value can be used to provide a very explicit module with a special functional capability. | If you usually get invoices of a partner, which always looks same, you might provide a handle to parse this invoice, and preview the information needed for the antuser. Perhaps only the sum, the categories of articles or the target adress. This priority highly depends on the workflow of the antusers and should be used very restrictevly. |
Usage
As you might noticed the IModuleSelector
and its parameter can only be understood in the concrete context. To get some information about it, you might look into this documentation or the comments above the definition of the parameters type.