[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

>trying to understand dependency injection

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 3

File: 1476836294805.png (30KB, 221x228px) Image search: [Google]
1476836294805.png
30KB, 221x228px
>trying to understand dependency injection
>>
Why does enterprise have to so confusing and abstract about everything?
>>
>>61549486
Just put your db functions into a class, and extract a public interface. Then when you new up the thing that needs instance, pass a refer to the db via it's interface.

Injection just makes maintaining that code down the line after 35 street shitters have fucked with it easier. It ain't all that hard or special
>>
File: 1485276834923.jpg (5KB, 192x154px) Image search: [Google]
1485276834923.jpg
5KB, 192x154px
>>61549640
>trying to understand code at work
>frameworks and shit all over the place
>random stuff getting injected from who knows where, bunch of settings are coming from some xml files somewhere else
>>
>>61549486
Program has a list inside of it of it's dependencies. The dynamic linker looks at this list and locates said dependencies for the program. You can use preloading to provide your own library in place of a requested one, or you can inject a dependency into the binary's memory, or modify the binary on-disk to ask for a new dependency. You can then use the library to override or switch out functions the binary would normally use, like so:

binary:
print("Hi")
print(random())

Legit Library:
def random()
random(1..65554)
end

Malicious New Library:
def random()
return 6
end

This allows you to control the binary's execution to a degree.
>>
>>61549710
This doesn't sound right.
>>
File: 1423717350198.jpg (32KB, 400x291px) Image search: [Google]
1423717350198.jpg
32KB, 400x291px
>>61549486
>>61549640
Jesus, this was me just months ago
>Decide to take a course on Java EE because why not
>It's all a bunch of weird and verbose abstractions with @ annotations all over the fucking place that not even the instructor can explain well
>Finish said class and uninstall all the shit I had to use like I was burning a witch in the middle ages
It gave me a whole new appreciation for writing the code I always wrote and not that garbage. I'd rather be unemployed and starve than take a job related to it.
>>
>>61549486
what do you reading?
>>
>>61549486
Objects need other objects to do stuff, and they need to get them from somewhere. If you hardcode a way they get them (a singleton, or creating an object in code), shit gets impossible to unit test. So instead you create the stuff the object needs beforehand and give all of it to them first (in the constructor for example). If your thing needs to create new objects that you wrote, then give him an object maker too so you can make mock objects in unit tests.

This can become wordy when you have many objects you have to pass in multiple places, so sometimes you can use magic decorators for attributes or arguments that are equal to saying "just pass this thing down" or "just add / grab this thing in the constructor".
>>
>>61551552
so this DI is made just for convinient testing?
>>
>>61552003
And decoupling so that it's easier to make changes without breaking stuff
>>
>>61552305
thanks
do you have any literature on mind
or wikipedia is sufficient?
>>
>>61552481
Not really. I'm having trouble fully understand it myself and most of what I get is from seniors at work
>>
>tfw dependency injection in javascript is the easiest fucking shit in the world

I don't even read the error text anymore I just recognize what type of issue it is by the shape of the red error vomit that fills up my entire browser console.
>>
>>61549486
>Letting methodology fags like Fowler make up terms for passing functions or objects with specialized methods for the sake of the loose coupling of data and function.
>>
IT'S JUST CALLBACKS, JESUS CHRIST.
>>
>>61554373
how's that?
Thread posts: 17
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.