eduherminio / AoCHelper

Helper .NET library for solving Advent of Code puzzles

Home Page:https://adventofcode.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Solver without static context?

jetersen opened this issue · comments

Would be nice if I could dependency inject the solver.

What you've done in your pull.ps1 I have done in C# by injecting a http client.

Could you provide some more context about the scenario where you want the Solver to be injected via DI?
It used to be non-static, but from v0.8.0 I decided to go down the static path and make the base problem class more extensible instead.

I want the solver to actually have access to the base problem with a fetch input method for that I need a http client which I started using dependency injection for the use case.

The fetch input will attempt to check if the InputFilePath exists if not go fetch the input file.

Something you can do is creating your own CustomBaseProblem class, inheriting either BaseProblem or BaseDay, and either doing that conditional fetching in the constructor or in an overridden FileInput getter property.
I'm aware that such a solution doesn't allow DI though, but I'm afraid I don't have plans to make the Solver non-static for the time being unless there's more demand for it.

I ended up implementing the solver for my needs.

Solver is mixing the table drawing and solving parts.

I changed the solver to accept tasks and create a separate method for drawing since working with asynchronous tasks does not work well when drawing 🙈

The solve methods does not work with the table and clearing of terminal at all.
Makes the code easier to read using expression bodies.

The solver now also works with dependency injection to load all the problems.

That's terrific @jetersen, looking forward to seeing the result of it if you ever decide to open source it.

Looks great @jetersen, I'll let you know if at some point I go back to the non-static Solver idea, in case we can rejoin our paths.

@jetersen Can I kindly ask you to add the MIT license to your repo?
You can (and should!) add your name under mine there, but keeping a copy of the original license and attribution is a requirement (almost the only one) for any derivate work.

I was going to. No worries 🙈

Do you want the license in the files? or just in the outer LICENSE file?

The outer license file is fine for me, thanks!