Skip to content

Commit d47a251

Browse files
committed
No words more than 10
1 parent 5dc1082 commit d47a251

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

_posts/2007-03-30-dependency-injection-explained.md

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,57 @@ blogger_id: tag:blogger.com,1999:blog-36533086.post-340487749415014671
1111
blogger_orig_url: https://www.marcusoft.net/2007/03/dependency-injection-explained.html
1212
---
1313

14-
When I first read about Dependency Injection, I of course read the
15-
[famous article](http://www.martinfowler.com/articles/injection.html) by
16-
Martin Fowler... and to you I can say that I didn't get it. At all.
17-
Please don't tell anyone ;)
14+
When I first read about Dependency Injection, I of course read the [famous article](http://www.martinfowler.com/articles/injection.html) by Martin Fowler... and to you I can say that I didn't get it. At all. Please don't tell anyone ;)
1815

19-
But after the presentation at [Avega](http://www.avega.se) by [Niclas
20-
Nilsson](http://www.niclasnilsson.se/) I finally got it. And the exemple
21-
below is a small rip of the DI-part of the presentation but it works as
22-
a reminder for me anyway.
16+
But after the presentation at [Avega](http://www.avega.se) by [Nicias Nilsson](http://www.niclasnilsson.se/) I finally got it. And the example below is a small rip of the DI-part of the presentation but it works as a reminder for me anyway.
2317

2418
Here we go:
25-
Lets say that we have a class called SalesController that managers the
26-
business logic for sales. In order to work it has to get some product
27-
information which is stored in a reposotory calles ItemInventory.
19+
20+
Lets say that we have a class called SalesController that managers the business logic for sales. In order to work it has to get some product information which is stored in a repository called ItemInventory.
2821

2922
Below is a example implementation of SalesController
30-
`public class SalesController{ ItemInventory item; public SalesController() { ... } ...}`
31-
This means that the SalesController is dependent to ItemInventory. That
32-
is not that good since:
3323

34-
- if you want to exchange ItemInventory for another implementation it
35-
will have major impact on SalesController
36-
- the SalesController is quite hard to test, which in turn has to do
37-
with it being hard to isolate, or simpler you can't mock-up
38-
ItemInventory in a easy way
24+
```c#
25+
public class SalesController {
26+
ItemInventory item;
27+
public SalesController() {
28+
//...
29+
}
30+
//...
31+
}
32+
```
33+
34+
This means that the SalesController is dependent to ItemInventory. Thatis not that good since:
35+
36+
- if you want to exchange ItemInventory for another implementation it will have major impact on SalesController
37+
- the SalesController is quite hard to test, which in turn has to do with it being hard to isolate, or simpler you can't mock-up ItemInventory in a easy way
3938

4039
Lets use interfaces instead:
41-
`public class SalesController{ IItemInventory item; public SalesController() { ... } ...}`
42-
We have now won that we easy can exchange ItemInventory against another
43-
class that implements IItemInventory. But is still is(can be) hard to
44-
test since you have to test ItemInventory as part of the test of
45-
SalesController.
40+
41+
```c#
42+
public class SalesController {
43+
IItemInventory item;
44+
public SalesController() {
45+
//...
46+
}
47+
//...
48+
}
49+
```
50+
51+
We have now won that we easy can exchange ItemInventory against another class that implements IItemInventory. But is still is(can be) hard to test since you have to test ItemInventory as part of the test of SalesController.
4652

4753
Dependency Injection to the fore!
48-
`public class SalesController{ IItemInventory item; public SalesController(IItemInventory item) { this.item = item; } ...}`
49-
In this way we can send in the dependency of the class (ItemInventory in
50-
this case) to SalesController, or if you rather want we can **inject the
51-
dependency** of SalesController.
5254

53-
Now we can, in a testcase, send in a mock-up of ItemInventory to easy
54-
test the methods of SalesController.
55+
```c#
56+
public class SalesController {
57+
IItemInventory item;
58+
public SalesController(IItemInventory item) { this.item = item; }
59+
// ...
60+
}
61+
```
62+
63+
In this way we can send in the dependency of the class (ItemInventory in this case) to SalesController, or if you rather want we can **inject the dependency** of SalesController.
64+
65+
Now we can, in a testcase, send in a mock-up of ItemInventory to easy test the methods of SalesController.
5566

56-
Very short, to end this mega-post, Spring.NET gives you the possibility
57-
to do these injections via configuration-files, which further simplifies
58-
the testing process (i.e. a different config-file for the test-code).
67+
Very short, to end this mega-post, Spring.NET gives you the possibility to do these injections via configuration-files, which further simplifies the testing process (i.e. a different config-file for the test-code).

_posts/2018-12-14-make-a-copy-of-github-repo---the-script-way.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Now you can ask the students to `git clone https://github.com/marcusoft/salt-jsf
5656

5757
Notice that the name of the organization (or user) needs to be included in repository name (`marcusoft/salt-jsfs-reactstarter` for example)
5858

59-
## TL;DR - For the love of God - just give me the script!
59+
## TL;DR - For the love of God - just give me the script
6060

6161
Ok. Ok. Ok.
6262

@@ -102,4 +102,3 @@ And then run it with `bash cloneRepository.sh organization orginal-repo new-repo
102102
## Summary
103103

104104
This was pretty fun to work with. That `hub` command opened up the possibilities and made for a nice, short and useful command.
105-

0 commit comments

Comments
 (0)