7.0: CreateRefactor
Refactor CreateNoteService
CreateNoteService
Open ElevenNote.Web -> Controllers -> NoteController
Click and drag down the button at the top right corner of the window so it splits the code into 2 sections. This is so you can see things at the top and bottom of the file at the same time.
Notice that the same 2 lines are repeated
Select this code in the
Create
methodGo to Edit -> Refactor -> Extract Method
Rename the new helper method
CreateNoteService()
Change
NoteService
tovar
Notice how it abstracts out the code so that it is usable in all
ActionResult
methodsTIP: Do not try to instantiate a
Service
inside of the constructor. The MVC framework does not have the data available that may be needed.
Next, we'll add some validation messages.
Last updated