The purpose of this architecture document is to propose a standard layout for DSC modules which allows for rapid creation of class-based resources by abstracting away some of the complexities and redundancies of resource creation.
The end result of this design is that a resource creator should only ever need to create 3 files to have a functional, high quality resource - and those files only need to focus on the properties, and the procedures for getting and setting those properties from the system.
Obviously, examples and test will be needed too for a truly high quality resource. I'd like to think we could tackle that at a later date.
The DscResource.Common PowerShell module provides a set of common functions to DscResources to accelerate their creation. This module would be leveraged in the same capacity to provide a base class from which all other class-based resources can inherit. The DscResource.Common module would also provide additional functions to provide all functionality for the Test() method of the base class and for standard class conversions that may be required (see DnsServerDsc/DnsRecordBase/TTL property for an example representing a TimeSpan as a String).
The new module would leverage the current structure provided by Sampler with specific usage:
- The
Classesfolder will hold the class files for each resource in the module.- Note: Classes should not do input validation. That should be left to the
Get-*andSet-*functions instead (there is more flexibility in validation functionality withValidate-Script, etc.). - Note: managing localization data occurs here as well.
- Note: Classes should not do input validation. That should be left to the
- The
Publicfolder will contain Get and Set functions for each resource- For example, if the resource is named
ApplicationProperty, thenGet-ApplicationPropertyandSet-ApplicationPropertywould reside in thePublicfolder.
- For example, if the resource is named
- The
Privatefolder would be used for any functions called by the Get and Set functions which are specific to the functionality of this resource/module.
When the LCM calls Get() on a given resource (in this scenario, the resource is named ApplicationProperty):
- the
Get()method in the base class (fromDscResource.Common) is called - the base class calls the
ConvertFrom-StringParameterfunction as many times as necessary to translate class types appropriately to pass parameters correctly in the next step - the base class calls the
Get-ApplicationPropertyfunction in the resource module'sPublicfolder Get-ApplicationPropertyreturns a hashtable representing the properties of theApplicationPropertyclass- the base class calls the
ConvertTo-StringParameterfunction as many times as necessary to translate class types appropriately to populate fields correctly in the next step - The
Get()method of the base class creates an empty instance ofApplicationPropertyand populates the fields with data from the hashtable - The
ApplicationPropertyclass returns the object to the LCM
- Participants colored green are members of the
ApplicationDscmodule- Participants colored blue are members of the
DscResource.Commonmodule
Likewise, when the LCM calls Set() on a given resource:
- the
Set()method in the base class (fromDscResource.Common) is called - the base class calls the
ConvertFrom-StringParameterfunction as many times as necessary to translate class types appropriately to pass parameters correctly in the next step - the base class calls the
Set-ApplicationPropertyfunction in the resource module'sPublicfolder Set-ApplicationPropertyperforms the set operation
- Participants colored green are members of the
ApplicationDscmodule- Participants colored blue are members of the
DscResource.Commonmodule
However, test functionality is encapsulated in the DscResource.Common module:
- the
ApplicationPropertyclassTest()calls the base class'Test()method - the base class gets its current properties (desired state) as a hashtable from
ConvertTo-Hashtable - the base class calls its
Get()method (see previous Get() section for flow details) - the base class takes the object returned from
Get()and passes it toConvertTo-Hashtableto store the current state of the system - the base class calls
Test-DscParameterStateto compare the desired and current state hashtables and returns the result back up the stack to the LCM
- Participants colored green are members of the
ApplicationDscmodule- Participants colored blue are members of the
DscResource.Commonmodule
See the code in the Pseudocode folder for an example of how this could play out in practice.



