> For the complete documentation index, see [llms.txt](https://eleven-fifty-academy.gitbook.io/dotnet-201-elevennote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eleven-fifty-academy.gitbook.io/dotnet-201-elevennote/elevennote-parts-1-11/part-7-create-refactor/7.0-createrefactor.md).

# 7.0: CreateRefactor

## Refactor `CreateNoteService`

1. Open **ElevenNote.Web -> Controllers -> NoteController**
2. 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.

   ![Drag Button](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxNAvtkas0IMEe4L3A%2F-LAxNCwbsArK-2jQa8vg%2F7.0-A.png?generation=1524669409492437\&alt=media)
3. Notice that the same 2 lines are repeated

   ![Repeated Lines](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxNAvtkas0IMEe4L3A%2F-LAxNCxsfBld2SjI3TTx%2F7.0-B.png?generation=1524669410885617\&alt=media)
4. Select this code in the `Create` method

   ![Code to Select](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxNAvtkas0IMEe4L3A%2F-LAxNCzVXauWSsxW_gDt%2F7.0-C.png?generation=1524669410810989\&alt=media)
5. Go to **Edit -> Refactor -> Extract Method**

   ![Refactor](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxNAvtkas0IMEe4L3A%2F-LAxND0uzpD5A0zpeuNy%2F7.0-D.png?generation=1524669410068500\&alt=media)
6. Rename the new helper method `CreateNoteService()`

   ![New Method](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxNAvtkas0IMEe4L3A%2F-LAxND2b5pOFsFL8GjGr%2F7.0-E.png?generation=1524669409617317\&alt=media)
7. Change `NoteService` to `var`

   ![Var](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxNAvtkas0IMEe4L3A%2F-LAxND5i0aLzdRFycQ3p%2F7.0-F.png?generation=1524669411794450\&alt=media)
8. Notice how it abstracts out the code so that it is usable in all `ActionResult` methods
9. **TIP:** *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,](/dotnet-201-elevennote/elevennote-parts-1-11/part-7-create-refactor/7.1-validationmessages.md) we'll add some validation messages.
