-
Notifications
You must be signed in to change notification settings - Fork 255
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
Remove the Hacks where you access Chocolatey's SimpleInjector.Container #436
Comments
@ferventcoder I literally just changed it so that GetSources now uses the background process instead haha. And the reason for that Hack is historical, but largely because there was no way do something I need to do though Chocolatey.Lib and it seemed like a pain at the time to bend the API to do it, so I just decided I'd grab the underlying service I needed directly. In this case, there was no elegant way to get sources in the way I needed (and I believe something else), so I opted to just grab the sources straight from the config file. I'd love to work on getting rid of that Hack though. I can research into it again to see why I needed it in the first place. |
Yup, I'm about 90% sure the reason for that hack is so I could get the If we can get APIs in place to list all the above through the API, I'm pretty sure I could remove all the hacks. |
More to the question here of what stops you fron setting up directly to IPackageInformationService and its implementation? |
GetSources is the one I found. :) |
@ferventcoder What do you mean? If I'm understanding correctly, the biggest reason I didn't just instantiate PackageInfoService directly is either it, or some important part of creating it (like an injected dependency) was internalized. And honestly, it really is a hack. I'd very much like to replace it with an "official" way. |
None of the injected dependencies are "internalized" that I am aware of, but it could be that there is a state in something that you'd want to come from Chocolatey. |
That might have been it. Hence me just asking Chocolatey to create it for me. |
Going to add a way for you to query the container directly to the api. |
That works too :) |
chocolatey/choco#1294 Should remove most of the hacks code. |
Awesome! |
(GH-436) Remove hacks for accessing chocolatey internals.
Is there a chance we can remove this?
ChocolateyGUI/Source/ChocolateyGui.Subprocess/Hacks.cs
Lines 47 to 87 in 13d0d0f
Took me awhile to discover this one - accessing internals from something else can lead to really hard to find bugs. Here's a hint on the bug - chocolatey/choco@61cd084
Details
ChocolateyService.GetSources()
is one of the first things to run in the subprocess - note it makes a call to the Hacks file which accessesSimpleInjector.Container
.Lets.GetChocolatey()
is called and then tries to load licensed code registration into the container, however it can't because the container has already been accessed.Workaround
The fix I have for this now is to call
Lets.GetChocolatey()
inProgram.Main()
when the process is setting up so that everything gets registered properly prior to callingGetInstance
.Fix
I may not fully be aware of the reasoning here, is there a reason this is being used over setting those items up in a container specifically for the GUI?
I spent more time that I want to admit wrestling with why I could not get the Licensed code to set up properly.
Other Thoughts
I did spend quite a bit of time making the lib code a bit more robust, so at least there is that.
I'll be pushing back some PRs once I get all of this cleaned up.
The text was updated successfully, but these errors were encountered: