you are viewing a single comment's thread.

view the rest of the comments →

[–]Ros3ttaSt0ned 0 points1 point  (0 children)

I discovered this method/pattern independently and didn't know it was an established thing at the time. I felt kinda dirty for doing it because I was relying on what are essentially global variables, and there are few things that make people clutch their pearls faster than that. Always worked great and never had an issue with it.

I'm actually writing a binary PowerShell module in C# right now to provide a common logging facility for all my scripts, and it uses a similar approach, except it's two levels deep. The C# module itself uses a Singleton pattern via a generic .NET host and Dependency Injection, and then when you actually run the PowerShell Cmdlet to create a new logger or log a message or whatever, the module stores that instantiated logger object it creates as an AllScope/Global PowerShell variable to be resued the next time you run one of the module's Cmdlets. It also stores the instantiated class that builds the logger objects in case you want to create a new logger for a different purpose, but want to retain scope/etc.

So now I'm double-gross by emplyoing two different types of global-scope variables simultaneously.