Timeline for Dependency Injection: Field Injection vs Constructor Injection?
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 5, 2018 at 22:21 | history | edited | Robert Harvey | CC BY-SA 3.0 |
added 7 characters in body
|
| Oct 18, 2016 at 21:42 | history | edited | Robert Harvey | CC BY-SA 3.0 |
deleted 99 characters in body
|
| Aug 4, 2016 at 15:47 | history | edited | Robert Harvey | CC BY-SA 3.0 |
added 1 character in body
|
| Oct 30, 2015 at 13:07 | comment | added | Binary Worrier | +1: Yes, no magic in the C# version. It's a standard class, it has dependencies, they're all injected at one point, before the class is used. The class can be used with a D I container, or not. Nothing in the class says it IOC or "Automatic Dependency Injection" framework. | |
| Oct 24, 2015 at 1:27 | comment | added | Eric B. | No - I'm not talking about test classes. I'm talking about production classes. It just happens that the example in the discussion group is a unit test, since the framework is a mocking/testing framework. (The whole discussion revolves around if the mocking framework should support constructor injection) | |
| Oct 23, 2015 at 20:45 | comment | added | Robert Harvey | If you're only talking about test classes, it may not matter. Because, test classes. | |
| Oct 23, 2015 at 19:57 | comment | added | Eric B. | If you look at the first post in that discussion you'll see I have almost the exact same defn in my Repo class. | |
| Oct 23, 2015 at 19:48 | comment | added | Eric B. |
Unless I read your post wrong, you are not actually looking at the example properly. My implementation of VeracodeService is nearly identical to the one you wrote (albeit in Java vs C#). The VeracodeServiceImplTest is actually a Unit Test class. The @Injectable fields are essentially mocked objects being inserted into the context. The @Tested field is the object/class with the DI Constructor defined. I agree with your viewpoint that prefers Constructor injection over field injection. However, as I mentioned, the JMockit author feels the opposite and I am trying to understand why
|
|
| Oct 23, 2015 at 19:11 | history | answered | Robert Harvey | CC BY-SA 3.0 |