Anatomy of nspectre
I’ve been meaning to blog about the anatomy of nspectre for a while now. nspectre consists of 2 distinct parts: configuration and a runtime.
The configuration has at its root the Settings class in the NSpectre.Core.Configuration namespace. This namespace also contains a couple of implementations of IConfigurationReader that read XML into the configuration, which can be thought of as a (sort of) Domain Specific Language (DSL.) The DSL provides a means to model the conditions required for a type to be valid for a given action. The reason I say sort of DSL is that the templates are, essentially, C#. However, by leveraging CustomSpecifications, these templates can be abstracted.
The main class in the runtime is IValidator. To create an instance of IValidator, you use IValidatorFactory – and to get an instance of IValidatorFactory you create an instance of Initialiser. The implementation of IValidatorFactory compiles the Settings the first time an instance of IValidator is requested.