Class QuirksDataProvider
- Namespace
- CSF.Extensions.WebDriver.Quirks
- Assembly
- CSF.Extensions.WebDriver.dll
Implementation of IGetsQuirksData which can merge together a primary and secondary source of quirks data, providing data-shadowing capabilities.
public class QuirksDataProvider : IGetsQuirksData
- Inheritance
-
QuirksDataProvider
- Implements
- Inherited Members
Remarks
This type provides two constructors and its behaviour will differ depending upon which is used. If this object is constructed with only one parameter, either a QuirksData or an IOptions<TOptions> of QuirksData - but not both - then the GetQuirksData() method will return an object which contains the same values as that source data.
If the constructor QuirksDataProvider(IOptions<QuirksData>, QuirksData) is used with both parameters specified then the return value from GetQuirksData() will be an object that contains data resulting a merge of the data from those two sources.
The merge algorithm used in the scenario noted above is:
- Where the options-based source data and the plain object data specify quirks that the other does not have, the result will have both quirks
- Where both the options-based and the plain object source data specify the same quirk, the affected browsers from the options-based data will shadow (aka 'replace' or 'override') those from the plain object
- Neither input object will be altered by this process; the results from GetQuirksData() will be based upon a new object
The purpose of this algorithm is to permit an application to ship with a set of hard-coded quirks data. This might be an in-memory object or read from a JSON embedded resource or similar. This in-memory data may then be added-to and/or overridden (shadowed) by end-user-specified options, using the Microsoft Options Pattern. This allows end consumers to quickly react to changes in browser support via an options/configuration change, even if a library which provides a set of quirks data has not yet been updated.
Constructors
QuirksDataProvider(QuirksData)
Initialises a new instance of QuirksDataProvider with only some in-memory source data.
public QuirksDataProvider(QuirksData quirksData)
Parameters
quirksData
QuirksDataThe source quirks data
Remarks
This constructor will initialise the object using a direct copy/clone of the data within quirksData
.
See the remarks upon QuirksDataProvider for more information about the available constructors.
Exceptions
- ArgumentNullException
If
quirksData
parameter is null.
- See Also
QuirksDataProvider(IOptions<QuirksData>, QuirksData)
Initialises a new instance of QuirksDataProvider with quirks data options provided by the Microsoft Options Pattern, and optionally some in-memory source data with which to merge the options data.
public QuirksDataProvider(IOptions<QuirksData> optionsData, QuirksData quirksData = null)
Parameters
optionsData
IOptions<QuirksData>Source quirks data from the Microsoft Options Pattern
quirksData
QuirksDataIn-memory source quirks data
Remarks
If the quirksData
is null or empty then this constructor will
initialise the object using a direct copy/clone of the data within optionsData
.
If both parameters are specified then the merge algorithm described in the remarks of
QuirksDataProvider will be used to merge these two data-sources together.
Exceptions
- ArgumentNullException
If
optionsData
parameter is null.
- See Also
Methods
GetQuirksData()
Gets the source data for browser quirks, using state available in the current instance.
public QuirksData GetQuirksData()
Returns
Remarks
Typically this data would come from dependency injected services/options. See AddWebDriverQuirks(IServiceCollection, QuirksData, bool, string) for more information about configuring this in a typical app.