Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Axel406324yMay I ask what language and how do you achieve dependency injection. I'm curious about the topic
-
Root797764y@Axel406 Ruby on Rails.
I have a WalletPass model that belongs_to the Order model so I can reference it by name from anywhere in the model. (Literally by just `order`)
The wallet pass methods I’m writing accept an optional order object (which defaults to the associated order). This way I can pass in nothing at a and have it operate on the associated order, or in specs I can mock an order and pass that into the method to have it operate on data from that order.
I also broke up the monolithic “generate_wallet_json” method into multiple that generate each piece, and ones that generate larger chunks. This way I can very easily add a new wallet pass type that includes different fields. That all follow the order injection pattern so I can spec them all in the same way without needing to generate the entire wallet pass for every spec.
This makes it sound fancy, but it’s really just a simple defaulted parameter. 🤷🏻♀️ -
Axel406324y@Root interesting, dependency injection topic is new to me.
I'm developing an app with JavaFX, MVC pattern and I had this problem where a module needs a service from another module. I did some research on what are the best practices and I learned about Spring framework for dependency injection.
To be honest I didn't try it, maybe I will someday because it looks really cool, I ended up using the Service Locator pattern, I have a singleton class that stores the needed instances of View and Model -
@Axel406 Young you are.
Learn you must.
Let guide be failure.
Yoda aside. A start.
I'd recommend to learn the basic principles without a framework. It will grt you a better understanding of how things _could_ cooperate together. It's very hard to understand this in a full fledged framework.
Many times, patterns built upon shared ideas / principles and just evolved in different things
I forgot what it was like to have a productive day!
I’m rewriting the Apple wallet pass code to make it fully customizable instead of mostly static, and it’s beautiful.
The code was horrible tangled spaghetti before (and soo slow) but now it’s clean and fast and modular and absolute bliss to spec. Yay, dependency injection!
I actually had fun working today! 😊
It’s been the first time in months.
random
i forgot code can be fun
root has a good day