microsoft / Requirements

PowerShell framework for declaratively defining and idempotently imposing system configurations
MIT License
159 stars 26 forks source link

Replace `Import-Module` and `.` with `using module` #55

Open chriskuech opened 4 years ago

chriskuech commented 4 years ago

We heavily rely on classes, which don't integrate well with Import-Module, which forces us to dot source a lot. using module should solve our import woes.

Stephanevg commented 4 years ago

Hi @chriskuech Be carefull, as that would expose all your classes to the end user, and they could end up polluting his session. It is possible to export classes by using a 'hybrid approach'. When you boil it down to the bare minimum, it is nothing more than wrapping the instantiation of a class in a function starting with the 'new-' keyword. Example, if you have a class called CustomRequirement you can do this.


Function New-CustomRequirement {
    Param(

     )
     return [CustomRequirement]::New() #possible to work with overloaded constructors and parameter sets.
}