Comments (3)
🚂 🚋 🚋 <-- 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.
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.
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)
- Enhancement of Authentication and Authorization Filters to Allow Custom Configurations and Stability Improvements HOT 4
- Data race with various client APIs HOT 3
- Allow to ignore globalPredicates for specific resources HOT 1
- Undefined SwitchMetric Error with client-go 0.30.0 in Go Vet HOT 8
- Use setup-envtest from (test) code HOT 18
- Semantic version is incorrect for setup-envtest HOT 3
- Default Liveness and Readiness endpoints return 404
- Optimize patches returned by Defaulter
- DefaultLabelSelector overrides ByObject.Label in DefaultNamespaces
- Does controller-runtime support that multiple controllers share one Manager and use different clients(RBAC)? HOT 6
- Add a way to grab the controller name out of the reconcile context HOT 1
- failed to install setup-envtest HOT 1
- How to change DefaultNamespaces at runtime HOT 3
- Reconcile is triggered after status update HOT 4
- Upgrade problem (v0.15.2->v0.17.3): configuring namespace HOT 2
- [BUG]: goroutine leak when `leaderelection.NewLeaderElector` return error
- [issue] regarding horizontal scaling for operators
- [bug] setup-envtest unable to find version for linux HOT 8
- go install fails with "zip: not a valid zip file" error message HOT 1
- setup-envtest is stuck and fails to download any k8s version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from controller-runtime.