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
0 answers

trying to use /dev/uinput to turn on built-in webcam

Basically, I would like to turn on my notebook's built-in webcam from a shell or shell script, without having to phisically press Fn+ESC every time I want to turn it on. I've been trying to activate the integrated webcam in my lemote yeeloong 8089B…
voscarmv
  • 11
  • 4
0
votes
1 answer

Mootools inject not working on ul correct

In page I have that code:
  • Name 1
  • Name 2
  • Name 3
  • Name 4
And I try to inject some of these code:
  • Name 5
  • Name 6
  • Name 7
  • before
    Donatas Veikutis
    • 974
    • 2
    • 15
    • 36
    0
    votes
    1 answer

    Mootools inject after not working

    Mootools code: window.addEvent('domready', function() { var homeLink = $$('a.pathway'); new Element('a', {'href': '/ru/produktsiya', 'html': 'Click me!'}).inject(homeLink, 'after'); }); Why didn't work?
    Footniko
    • 2,682
    • 2
    • 27
    • 36
    0
    votes
    1 answer

    Injecting Javascript to Iframe

    I am making a live editor for my website. I have the CSS and HTML parts down, only issue is the JS part now. Here is a snippet of the code var frame = $('#preview_content'), contents = frame.contents(), body =…
    EasyBB
    • 6,176
    • 9
    • 47
    • 77
    0
    votes
    5 answers

    Combine hash keys if values are same

    I need to take a hash like this: {"10am - 2pm"=>"Sun - Sat", "5pm - 7pm"=>"Sun - Sat"} and create a new hash like this: {"10am - 2pm, 5pm - 7pm"=>"Sun - Sat"} If any values are the same amongst members in a hash, I need to combine the keys and…
    djibouti33
    • 12,102
    • 9
    • 83
    • 116
    0
    votes
    2 answers

    Javascript : Inject inline code to a html tag

    I would like to add my Google Analytics tracking event code inline to my input html tag : to have something I'm…
    user2136421
    0
    votes
    2 answers

    SQL Injection : Syntax error

    I have an essay on SQL injection ( what it is - how its done and how can it be avoided ). I get what it is and how it works. But i dont seem to be able to reproduce an injection on my database. I made a pretty simple database ,using mysql…
    Silas
    • 125
    • 2
    • 11
    0
    votes
    1 answer

    Where does an event go when injecting it into /dev/input/eventx?

    I think I have read all post related with my query, some of them helped but I still can´t find the correct approach. Im trying to develope an app which has to inject touch events into the system. As I was reading if you dont have system signature…
    Carlos Morera
    • 377
    • 4
    • 12
    0
    votes
    0 answers

    Get sessionscoped cdi from requestscoped

    I want to inject a SessionScoped object which its already in session in another RequestBean, and its injecting it successfully but it seems its creating a new instance of the class instead of bringing me what its in the session at the moment. My…
    cri_sys
    • 472
    • 1
    • 5
    • 17
    0
    votes
    1 answer

    JavaScript injected through Chrome extension is not loaded

    I am trying to inject a JavaScript through a Chrome extension, but the script onload method is not called... var scriptURL = 'http://'+response.scriptUrl, scriptTag = document.createElement('script'); scriptTag.type =…
    0
    votes
    3 answers

    What method can be used to print variables as inject iterates through a range?

    Using method chaining I would like to amend the following code so that on each iteration the variables mult and n are printed. What method can help accomplish this? (1..3).inject {|mult, n| mult * n}
    Bodhidarma
    • 519
    • 1
    • 7
    • 25
    0
    votes
    1 answer

    How to inject dynamic javascript code into an iframe that already exists on parent page

    I am trying to inject code into an iframe but I haven't had any luck and I'm not sure why. I store my js code into a variable, which works properly at this point, into a variable called pixel_code. I then want to inject that code into the iframe.…
    0
    votes
    1 answer

    Win32 Form for dll injection

    I created a dll with form in it, and when we inject the dll the form open. But the problem it when I do it, the process that I injected to, stuck and I can't with him noting. here what I did. DWORD WINAPI MessageLoop(HINSTANCE hInstance) { …
    Idohadar
    • 1
    • 2
    0
    votes
    2 answers

    Injection in test when using Angularjs & requirejs

    I am trying to use AngularJS with RequireJS currently, but I do not know how to make the test work with injection. Without RequireJS we could, Impl PhoneListCtrl.$inject = ['$scope', '$http']; var PhoneListCtrl = ['$scope', '$http',…
    Edward
    • 939
    • 3
    • 10
    • 17
    0
    votes
    1 answer

    Call function inside JavaScript

    Since url JavaScript should be injected into the webview, could someone let me know how I can call addPoints() function inside of basic function in the following code?