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

Refactor command registration so it is autowired #2572

Closed
TheCakeIsNaOH opened this issue Feb 5, 2022 · 2 comments · Fixed by #2782
Closed

Refactor command registration so it is autowired #2572

TheCakeIsNaOH opened this issue Feb 5, 2022 · 2 comments · Fixed by #2782
Assignees
Labels
5 - Released Improvement NO RELEASE NOTES Should not be included in the release notes - not enhancing or fixing end product.
Milestone

Comments

@TheCakeIsNaOH
Copy link
Member

TheCakeIsNaOH commented Feb 5, 2022

As noted in a todo comment

//todo: #2572 refactor - this should be autowired
container.Register<IEnumerable<ICommand>>(() =>
{
var list = new List<ICommand>
{
new ChocolateyListCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyHelpCommand(container),
new ChocolateyInfoCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyInstallCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyPinCommand(container.GetInstance<IChocolateyPackageInformationService>(), container.GetInstance<ILogger>(), container.GetInstance<INugetService>()),
new ChocolateyOutdatedCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyUpgradeCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyUninstallCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyPackCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyPushCommand(container.GetInstance<IChocolateyPackageService>(), container.GetInstance<IChocolateyConfigSettingsService>()),
new ChocolateyNewCommand(container.GetInstance<ITemplateService>()),
new ChocolateySourceCommand(container.GetInstance<IChocolateyConfigSettingsService>()),
new ChocolateyConfigCommand(container.GetInstance<IChocolateyConfigSettingsService>()),
new ChocolateyFeatureCommand(container.GetInstance<IChocolateyConfigSettingsService>()),
new ChocolateyApiKeyCommand(container.GetInstance<IChocolateyConfigSettingsService>()),
new ChocolateyUnpackSelfCommand(container.GetInstance<IFileSystem>()),
new ChocolateyExportCommand(container.GetInstance<INugetService>(), container.GetInstance<IFileSystem>()),
new ChocolateyTemplateCommand(container.GetInstance<ITemplateService>()),
new ChocolateyVersionCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyUpdateCommand(container.GetInstance<IChocolateyPackageService>())
};
return list.AsReadOnly();
}, Lifestyle.Singleton);

Internal Issue

@pauby pauby added this to the 1.x milestone May 13, 2022
@TheCakeIsNaOH
Copy link
Member Author

Looking at the changes required after upgrading the SimpleInjector library from the linked code in this issue: #2436, it seems like the upgraded SimpleInjector 5.x has this autowire functionality built in.

So this issue will probably be most easily fixed by moving to a newer SimpleInjector version when moving to a newer .Net FX version.

@AdmiringWorm AdmiringWorm self-assigned this Aug 11, 2022
@AdmiringWorm AdmiringWorm modified the milestones: 1.x, 1.2.0 Aug 11, 2022
AdmiringWorm added a commit to AdmiringWorm/choco that referenced this issue Aug 11, 2022
This commit updates the way that commands are registered
by handling this automatically by iterating through the entire
Chocolatey CLI assembly and any valid extensions to find
commands that inherit from ICommand and add these to
the pending registration list.
AdmiringWorm added a commit to AdmiringWorm/choco that referenced this issue Sep 15, 2022
This commit updates the way that commands are registered
by handling this automatically by iterating through the entire
Chocolatey CLI assembly and any valid extensions to find
commands that inherit from ICommand and add these to
the pending registration list.
@AdmiringWorm AdmiringWorm added NO RELEASE NOTES Should not be included in the release notes - not enhancing or fixing end product. Improvement 5 - Released and removed Improvement 4 - Done labels Oct 19, 2022
@AdmiringWorm
Copy link
Member

🎉 This issue has been resolved in version 1.2.0 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Released Improvement NO RELEASE NOTES Should not be included in the release notes - not enhancing or fixing end product.
Projects
None yet
4 participants