-
Notifications
You must be signed in to change notification settings - Fork 42
Description
Prerequisites
- Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
- Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in
Get-Foo
cmdlet" instead of "Typo." - Verify Version: If there is a mismatch between documentation and the module on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.
Version
v2.0
Links
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 258 in 9a81631
### Enum properties PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 309 in 9a81631
### The Ensure property PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 365 in 9a81631
### Complex properties PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Lines 559 to 566 in 9a81631
> [!NOTE] > The class defined for the **Reasons** property is named `MyModuleReason` instead of `Reason`, > using the module's name as a prefix. While you can give the class any name, if two or more > modules define a class with the same name and are both used in a configuration, PowerShell raises > an exception. > > To avoid exceptions caused by name conflicts in DSC and machine configuration, always prefix the > name of the class you define for the **Reasons** property. PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 794 in 9a81631
## Best practices
Summary
If a class or enum is defined with the same name in more than one module, compiling configurations that use both of those modules fails due to the name collision.
Details
We already partially cover this problem for defining the Reasons property for machine configuration:
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Lines 559 to 566 in 9a81631
> [!NOTE] | |
> The class defined for the **Reasons** property is named `MyModuleReason` instead of `Reason`, | |
> using the module's name as a prefix. While you can give the class any name, if two or more | |
> modules define a class with the same name and are both used in a configuration, PowerShell raises | |
> an exception. | |
> | |
> To avoid exceptions caused by name conflicts in DSC and machine configuration, always prefix the | |
> name of the class you define for the **Reasons** property. |
We should generalize this note and advice and surface it wherever it makes sense.
Suggested Fix
We should document this behavior, suggest that authors prefix their enums and classes with their module name, and add name prefixing to the best practices section for the Class-based DSC Resources article.
We may want to add an include that we can use throughout the documentation wherever we're talking about naming classes and enums for use as DSC Resource property types.