Przeglądaj źródła

Merge pull request #5 from vvmk/readme

Update the README to suggest constructor-based DI
Git-Leon 6 lat temu
rodzic
commit
cc4d312627
Brak konta powiązanego z e-mailem autora
1 zmienionych plików z 16 dodań i 4 usunięć
  1. 16
    4
      README.md

+ 16
- 4
README.md Wyświetl plik

@@ -108,8 +108,10 @@
108 108
 * Create a `PollController` class in the `controller` sub package.
109 109
 	* `PollController` signature should be `annotated` with `@RestController`
110 110
 
111
-* `PollController` has a `pollRepository` instance variable of type `PollRepository`
112
-	* `pollRepository` should be `annotated` with `@Inject`
111
+* `PollController` has a `pollRepository` instance variable of type `PollRepository`  
112
+
113
+* Create a constructor that accepts a `PollRepository` argument and assigns its value to the `pollRepository` member variable.  
114
+	* Mark the constructor with the `@Autowired` annotation.
113 115
 
114 116
 
115 117
 ### Part 3.1.1 - Create `GET` request method
@@ -273,8 +275,13 @@ public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
273 275
 ```java
274 276
 @RestController
275 277
 public class VoteController {
276
-    @Inject
278
+
277 279
     private VoteRepository voteRepository;
280
+    
281
+    @Autowired
282
+    public VoteController(VoteRepository voteRepository) {
283
+    	this.voteRepository = voteRepository;
284
+    }
278 285
 
279 286
     @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
280 287
     public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote
@@ -414,8 +421,13 @@ public class VoteResult {
414 421
 ```java
415 422
 @RestController
416 423
 public class ComputeResultController {
417
-    @Inject
424
+    
418 425
     private VoteRepository voteRepository;
426
+    
427
+    @Autowired
428
+    public ComputeResultController(VoteRepository voteRepository) {
429
+    	this.voteRepository = voteRepository;
430
+    }
419 431
 
420 432
     @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
421 433
     public ResponseEntity<?> computeResult(@RequestParam Long pollId) {