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
0
votes
1 answer

Inject Bean that uses @Named with value

how can I Inject a Bean, that uses a @Named annotation along with a value? @Named public class LanguageService{ ... } public class SomeOtherBean{ @Inject private LanguageService languageService } works without Problem - but how to…
dognose
  • 20,360
  • 9
  • 61
  • 107
0
votes
1 answer

Create a list from an array in Ruby

How do I convert this array: @list = ["one", "two", "three", "four"] Into a new array like this with the keys prepended: @new_list = ["1. one", "2. two", "3. three", "4. four"] using each and inject in Ruby?
0
votes
3 answers

Can't use @Qualifier along with @Inject and autowire="byType"

I have the bean config: and public class PostLoginUpdater implements PostLoginStatePersonalizer { //@Qualifier("CustomerManager") @Inject …
GarfieldKlon
  • 11,170
  • 7
  • 31
  • 33
0
votes
1 answer

GWT: Injected PlaceManager is null

On the code below I am injecting a PlaceManager on the 4th line, and trying to use the placeManager.revealPlace() on the last line. However, at that moment I get a null exception. Furthermore, if I add a if(placeManager==null){…
user411103
0
votes
5 answers

Merge values in a Hash

nodes = { :node1 => { :inherits => nil, :variables => { :foo => 1, :bar => 2 } }, :node2 => { :inherits => :node1, :variables => { :foo => 9, :baz => 4 } } } I've been trying to understand how to return a new nodes…
0
votes
1 answer

How do I inject hex into an assembly call of isoc99_scanf

I am working on a crackme and I have found a buffer overflow but when I enter \xNN, where N is anything between 0 and F, the \ and x are interpreted as their own values. I also tried \xNN. The program is a Linux executable so I am running it on…
0
votes
1 answer

Entering text into a textbox that doesn't belong to your application (C#/.NET)

So, I was just wondering how I could enter text into a text box on a web page with a windows application. Almost like a reverse screen scrape. I know I have read somewhere about being able to do this but, I completely forgot how he did it. I think…
Mashew
  • 561
  • 1
  • 5
  • 10
0
votes
1 answer

Protection from SWF Interception and Injection when loading child SWF

So here is the situation, I have a parent SWF that is load multiple child SWFs below it. I want to know if there is any way I can 100% trust that all of these child SWFs are mine. For instance, when loading child SWF "b.swf" from domain…
DominicEU
  • 3,585
  • 2
  • 21
  • 32
0
votes
5 answers

So maybe I'm not getting the idea in Ruby but I have a question about Enumerables inject

The |m,k| thing kind of throws me off. Does this have anything to do with order of precedence? m standing for 0 (or 1 in some languages) and k for the last in the Array/Hash whatever? So why do people put a number in .inject()? Alternatively, is…
0
votes
3 answers

How to inject EJB in java web service SOAP

i'm triyng to develop a simple web service in Java that used an EJB, with EJBs in jar file and WebServices in war file, both packaged in one ear. We use EjB 3.0 on JBOSS-AS 7.1. Here my EJB class with its interface : @Stateless public class TestEjb…
Nikoas
  • 11
  • 1
  • 1
  • 3
0
votes
1 answer

Inject method restful service

I have a bunch of RESTful web services(80) with @GET and @PUT methods. I want to add an @OPTIONS method to each service. Instead of manualy writing @OPTIONS method for each service I want to be able to inject them in the services. What is the best…
user1457881
  • 321
  • 2
  • 3
  • 10
0
votes
1 answer

Runtime error while obtaining PE headers from an application at runtime

I have been trying to make a executable injector into process for WINDOWS, the program compiles without any errors, but when I run the program (via Microsoft Visual Studio's Debug mode) I get a runtime error. Visual studio highlights a line (i have…
0
votes
3 answers

How to sum only the positive/negative values of the properties of objects in an array in Ruby

I understand that I can sum the properties of objects in an array in Ruby using the inject method. For example, I could sum the cash of all agents in an array using the following: sum_of_cash = agents.inject(0) { |sum, e| sum + e.cash } However,…
Spike Fitsch
  • 747
  • 1
  • 7
  • 12
0
votes
1 answer

how to inject Test-Implementation during tests, Production-Implementation in the production mode - Spring, JSR-330

Lets assume that I have sequencer and the following Beans. Sequencer is responsible for taking the next value from a database sequence. OracleSequencer is used in the production mode, TestSequencer during JUnit-Tests. public interface Sequencer{ …
dpolaczanski
  • 386
  • 1
  • 3
  • 18
0
votes
1 answer

How to execute an application that's injected in a process

I want to execute an application (executable ending with an .exe extension ) that is injected in a process on WINDOWS. How do I do that?
user1494517
  • 311
  • 1
  • 3
  • 11