Questions tagged [inject]

Design pattern to reduce coupling between components, by dynamically injecting into a software component dependencies that it needs to function.

Synonym for Dependency Injection

Dependency injection (DI) is a design pattern for object-oriented programming involving dynamically injecting (inserting) into a software component dependencies (service components) that it needs to function, without needing the dependent component to hard-code a dependency on the service. This reduces coupling between the dependent consumer and the service.

Resources / background questions

If you need a general introduction to DI you should refer to this question: What is dependency injection?

If you need a non-technical introduction you can refer to this question: How to explain Dependency Injection to a 5-year old.

If you would like to understand the relationship between DI and Inversion of Control (IoC), see Inversion of Control < Dependency Injection.

For book recommendations see Dependency Injection book recommendation(s)(dead link).

For general recommendations for writing DI-friendly code without a DI Container, see Dependency Inject (DI) “friendly” library.

If you are wondering why you should use a DI Container instead of Poor Man's DI, see Why do I need an IoC container as opposed to straightforward DI code?

If you are wondering what the Composition Root is, see What is a composition root in the context of Dependency Injection.

For potential downsides of using DI, see What are the downsides to using dependency injection?

Dependency injection and Inversion of Control are closely related. The difference between them is discussed at where-exactly-is-the-difference-between-ioc-and-di.

Also can read basic here : Dependency Injection For Beginner - 1

Related Patterns

1000 questions
-1
votes
1 answer

How to shell command inject a file

I have the following c program which is SUID. int execute(char *command, char *envp[]) { pid_t pid; int status=0; char *argv[] = {"/bin/bash", "-p", "-c", command, NULL}; if ((pid = fork()) < 0) { /* fork a child…
Ben
  • 129
  • 9
-1
votes
1 answer

custom ruby inject method not producing expected output

forgive me I see that this question has been asked in many ways here on forums but none have output the desired output and I have been stuck for a few days reading different explanations of how the inject method works. Could my code be inspected and…
aulbytj
  • 61
  • 8
-1
votes
1 answer

Why can my DLL only inject with manual mapping?

So I've made a DLL it involves a lot of code and I know it has worked before. I have since formatted my computer and updated my DLL. Using extreme injector the DLL will only inject using Manual Mapping. Which is fine but I would like to know what I…
-1
votes
1 answer

How to unload a DLL from a target Process?

I am working at an Injector but when I'm trying to Uninject / Unload the target Process, it's closing directly and I dont know why it's so. Here is the Code how I'm Injecting / Loading a DLL into a target Proces. The executionId is the target…
0xLyptox
  • 5
  • 4
-1
votes
1 answer

How do I inject or add data to my table as it isn't working?

I just cannot seem to update data in Swift! I am trying to build a radio player app for a friends radio station so when a song changes I need to update the playlist viewcontroller. The data from my Main View Controler is a instance of a struct. I…
Ryan
  • 9
  • 1
-1
votes
1 answer

Gulp watches/changes only main file instead of all files

I have problem with gulp watch task(i suppose) or with compiling files. I want gulp to watch all css files in styles folder, but it watches nad changes only the main index.html file and I can't see changes in the browser which I have made in css…
hedonist_ann
  • 23
  • 1
  • 4
-1
votes
2 answers

How to inject static field in static class in spring

I have the service MyStaticService which is doing some calculations using a DAO. How can I inject the MyDao object into the class field? I've tried to implement the setter with @Autowired but when I call doCalculations(..) the DAO is null. What am I…
CameronCoob
  • 81
  • 1
  • 11
-1
votes
1 answer

NullPointerException when using @Inject annotation

I got this error even thought I @Inject Message object in MyClass. I just try to learn it now how can I Inject an object. Please help me, Thanks! Here are my example. Main: public class Main { public static void main(String [] arg){ new…
Balázs Fodor-Pap
  • 438
  • 1
  • 5
  • 16
-1
votes
2 answers

@Inject Annotation not applicable Error shown?

I have created new project via Java Web->WebApplication->Enabled CDI My First question is: Why @Inject annotation showing error? even though bean.xml added.
Rence Abishek
  • 373
  • 1
  • 4
  • 16
-1
votes
1 answer

Spring 4 Component Inject with generic

I have encountered with the following issue. I would like to create Spring @Component with generic @Component public class ResponseDtoValidator { public ResponseEntity methodToInvoke(DTO dto) { return Optional.ofNullable(dto).map(result…
Igor Orekhov
  • 107
  • 7
-1
votes
1 answer

how to run console code for another site via our site

I want to write a function, in which I give 2 parameters to that. First parameter is URL of website in which I want run my code into this Website, and second parameter is JavaScript code which I want to run there. I want to inject my JavaScript code…
-1
votes
1 answer

In this case, why '--+' the comment style of mysql can work?

The example below comes from sqli-lab. In MySQL's doc(comment), the "-- " (double-dash followed by at least one whitespace) means a line's comment. It does work in some situation actually. My question is how it work in the example here, why it can…
-1
votes
1 answer

Send WM_NOTIFY from injected DLL or used __published function?

Hello. I'm have ListView control in another process. I wan't press click on ListView. Because windows forbiden send WM_NOTIFY throw process, i decide inject dll into app. When i try to send WM_NOTIFY message from injected dll, i'm get error…
r1se
  • 67
  • 1
  • 1
  • 6
-1
votes
1 answer

Unable to call method in managed dll after loading CLR. Why?

I have met some issues when trying to inject a dll into a process. I am quite new at the topic but am familiar with C# so reading and understand the syntax of C++ wasnt that unfamiliar and i understand it for the most part. What i am trying is only…
Dan-Levi Tømta
  • 796
  • 3
  • 14
  • 29
-1
votes
1 answer

how Inject/overrid code in function? best practice?

I got a big js lib witch I dont want to change because when they update the code I must update every time as well. So I want to inject or override as little as possible. And get my code in. The code of the lib and my code in it looks like this: var…
Cracker0dks
  • 2,422
  • 1
  • 24
  • 39