Coder Social home page Coder Social logo

Comments (3)

DirectXMan12 avatar DirectXMan12 commented on June 5, 2024

🚂 🚋 🚋 <-- the dependency injection train

At some point during the design of this framework, we had a discussion about dependency injection, and the upshot was that we were really hesitant about adding full-scale generic dependency injection, and decided to avoid it, and have a couple tightly scoped cases inside the library that didn't leak out (with the exception of InjectClient). I'm (so far) still on board with that sentiment.

My initial suggestion would just be to pass the logger in at object construction. If that's not possible for whatever reason, you could totally implement something similar to what we do internally -- things that need a Foo implement an InjectFoo interface, and then the code that has a Foo and a handle to those things checks each thing to see if it implements InjectFoo, and if it does, it calls that. Can you provide a bit more information on your particular usecase? Maybe some real or mock code that you're trying to achieve?

from controller-runtime.

grantr avatar grantr commented on June 5, 2024

Thanks for the background, I think the instinct to be wary of dependency injection is reasonable. Sounds like it's essentially an internal implementation detail. Since it's possible to call mrg.GetClient() when creating a controller, is there really a need to expose InjectClient? Maybe we (as users of the library) should drop our usage of that.

from controller-runtime.

DirectXMan12 avatar DirectXMan12 commented on June 5, 2024

I think the goal of that was probably to allow users to not have to write constructors -- with the Inject method, it's easy to just have a struct that contains your options as fields. It's a nice feature of the code, since you maintain readability by having field names matching with the values (you should see some of the constructors in kubernetes with identical parameter types next to each other and no indication of what they are when reading the calling code). You can also achieve that with an "options struct" pattern, mostly.

from controller-runtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.