7.0: CreateRefactor
Refactor CreateNoteService
CreateNoteServiceOpen 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
Createmethod
Go to Edit -> Refactor -> Extract Method

Rename the new helper method
CreateNoteService()
Change
NoteServicetovar
Notice how it abstracts out the code so that it is usable in all
ActionResultmethodsTIP: Do not try to instantiate a
Serviceinside 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