Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling interdependent classes #141

Open
iRon7 opened this issue Apr 19, 2024 · 3 comments
Open

Handling interdependent classes #141

iRon7 opened this issue Apr 19, 2024 · 3 comments

Comments

@iRon7
Copy link

iRon7 commented Apr 19, 2024

Background:

From my project, I have created a few PowerShell classes currently contained by a single file.
As the project is growing (the number and size of the classes), I would like to separate my classes over multiple files.
The problem with doing so is that the classes are interdependent.
see: Is it possible to declare two interdependent classes each in a separate file?

mcve setup:

  • Create two PowerShell files as shown in the StackOverflow question:
    • .\Source\Classes\a.ps1
    • .\Source\Classes\b.ps1
  • and a single module.psm1 file in the root containing:
. $PSScriptRoot\Source\Classes\a.ps1
. $PSScriptRoot\Source\Classes\b.ps1
Export-ModuleMember -Function a, b

The issue(s) with this are in fact shown by VSCode (the PSScriptAnalyzer)

2024-04-19_12h09_10

In the comment of the related StackOverflow question @TheMadTechnician, suggests that maybe this is something PSDepend could help.

If that is correct, can you show (or refer to) an example based on this mcve?

@iRon7 iRon7 changed the title Handling interdepended classes Handling interdependent classes Apr 19, 2024
@johlju
Copy link

johlju commented Apr 20, 2024

I think you looking for ModuleBuilder or create a new module project using Sampler's Plaster templates (which will build a module using ModuleBuilder).

@iRon7
Copy link
Author

iRon7 commented Apr 20, 2024

@johlju,

What I understand from the ModuleBuilder is that is pushes the author to setup a module according to certain guidelines (that only slightly differ from my own) and prepares the module for publishing. But issues #18, #35 and the line:

3. To force classes to be in a certain order, you can prefix their file names with numbers, like 01-User.ps1

Let's me believe that it won't resolve the issue of handling interdependent classes during the design (development and testing) phase...

@johlju
Copy link

johlju commented Apr 20, 2024

Nothing can help resolve that, unless an editor can parse and understand the AST (which I know none that can). For a class to be known during development (assuming the goal is intellisense) it needs to be loaded into the session, and a class that is loaded into a session cannot be changed unless starting a new session.

During testing you should build the module, then load the entire module in to a session, then run tests on the built module. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants