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
-2
votes
2 answers

When I inject the DLL into an existing process, DLLMain doesn't do anything

So I'm trying to make a game cheat (for learning purposes) and I'm using Counter Strike Global Offensive as the Target and I'm using -insecure launch option which doesn't allow me to go to any secure servers and thus I can only use the cheat in…
xXTurner
  • 61
  • 9
-2
votes
1 answer

Get DLL Module size after DLL injection without GetModuleInformation

I manual map dll and i can't get MODULEINFO for it's working region with GetModuleInformation (it's always answer for me with "Unable to obtain module")?. That happens because that function tries to get data from the module list in the process…
SLI
  • 713
  • 11
  • 29
-2
votes
2 answers

Injector doesn't inject dll

Wrote a simple Dll injector for "calculator.exe" process, with printing out some lines I confirmed that the injector did its job but the messagebox doesn't appear. Context: -void inject_dll(DWORD, char*) takes the ID of the process that I want to…
Arthur VP
  • 17
  • 5
-2
votes
1 answer

How can i see contents of buffer and compare with dll file?

I try to write dll injector with nativeApi. For this reason, i wrote this code. NtReadFile function reads something but i cant see anything except for the first value of FileReadBuffer. Also, i dont know anything about how does dll look into buffer.…
Burak Kocaman
  • 81
  • 1
  • 10
-2
votes
1 answer

Ruby inject nested loop

def max_subarr(arr) start_index, end_index = 0, (0...arr.length).inject([arr.first]) do |max_sub, i| (i...arr.length).each do |x| if max_sub.inject(:+) < arr[i..x].inject(:+) max_sub = arr[i..x] start_index, end_index =…
paulsus
  • 9
  • 3
-2
votes
3 answers

Manipulate HTML page via PHP

Hello I have INCLUDED a PHP file in the end of an HTML page. Now I want to add a style file before the end of the tag HEAD. But I need to do this via this php file, I have no choice. I have and index.php file and at the end of this file I am…
Ignacio Correia
  • 3,611
  • 8
  • 39
  • 68
-2
votes
1 answer

How can you inject a session reference

Can you inject a session reference into your class via structure map
monkeylee
  • 965
  • 3
  • 15
  • 32
-3
votes
1 answer

@Inject @ThirteenNumber throw NullPointException

I try to work with @Injection, so start with a simple example here : Interface public interface NumberGenerator { String generateNumber(); } BookService public class BookServices { @Inject @ThirteenNumber private NumberGenerator…
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
-3
votes
1 answer

Declaring Injection fields as static

Can I declare a Service injection as static in my Controller? For example : @Inject private static UserAttributeService userService; Update : My requirement was to initialize a Map in static block. The map will be unmodifiable, but it will be…
javaAndBeyond
  • 520
  • 1
  • 9
  • 26
-4
votes
2 answers

What does this malicious code injected into functions.php file do?

I have discovered some malicious code in a clients functions.php file. What is this doing, I have no idea. I'm OK with PHP but no expert for sure. Any ideas? if (!function_exists("b_call")) { function b_call() { if (!ob_get_level())…
Dave C
  • 262
  • 2
  • 6
  • 25
1 2 3
66
67