Dependency Injection in Cmdlets
TraGicCode opened this issue · 3 comments
TraGicCode commented
Is it possible or could a feature be done that allows the ability to perform dependency injection inside of our cmdlet's to ease the testing procesS?
JamesWTruher commented
@TraGicCode what would that look like? I'm not quite sure what you need to see in the nuget package.
rjmholt commented
@TraGicCode you're looking for a feature in PowerShell -- I would move this issue there. The PowerShell runtime is responsible for constructing cmdlets, and https://github.com/PowerShell/PowerShell is where new features are being added to that runtime. Note that:
- A new runtime feature like this would only appear in new releases of PowerShell, meaning it wouldn't be supported in older PowerShell versions, limiting the cross-version support of a module written against such functionality
- Dependency injection requires some smart reflection, making it relatively slow. That's usually fine for something like starting a web server or another service, where startup time isn't an issue. But when running commands, it means a performance loss. Even introducing the feature without using it means PowerShell must now do extra reflective analysis on each command to infer whether it needs to inject any dependencies or not. As always, any one feature like this isn't the straw that breaks the camel's back, but it all adds up.
TraGicCode commented
Hey,
Sorry for not getting back to this quickly enough. I’m only with closing this out since it’s not something I’ll be working or using anytime soon