Multi-File Modules with Classes

Hi!

If I want to make a module where each component function and class has its own file in the module folder (to make editing neater), how do I get this to work so that functions can access each other and all can use the classes?

I’ve read stuff where a PSM1 dot-sources separate files and exports their functions explicitly, and also references to specifying the files as Nested Modules in the PSD1. The latter seems to have issues with functions accessing each other unless you have multiple PSD1s - which seems a bit excessive if each nested “module” is going to contain only one function that you’d never be importing on its own.

I’ve not seen any reference to this topic where classes are specifically brought into it too. I need the classes to be usable both by the functions and also their being “exportable” by the module (i.e. visible to “using module”).

Thanks for any thoughts from anyone who’s battled with this already!

Classes cannot be exported from a module unless they are located directly in the psm1 file. There really isn’t a workaround there, you need them in the module file itself, before any functions are dot sourced.

Thanks Joel! That’s unfortunate but I guess it’s understandable :frowning:

If you want to develop the module having classes in separate files as well, you might implement a build step as part of a release pipeline where all class files’ contents are collated along with necessary parts of the PSM1 and you put together a new PSM1 before you release the module and use it in production.