Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 1.37 KB

01-Step01.md

File metadata and controls

35 lines (25 loc) · 1.37 KB

Step 1 - Adding a Controller

Let's go ahead and add a new Controller using Copilot!

  1. Select the Controllers folder in your Solution Explorer and then hit Ctrl+Shift+A

  2. In the dialog box name the file StoreController.cs

  3. In the C# file that loads you can use a prompt similar to the one shown to add the three methods (Index, Browse, Details) you need. Enter the prompt as a comment then hit enter.

    namespace CopilotMvcMusicStore.Controllers
    {
        public class StoreController
        {
            // add three methods named Index Browse Details
        }
    }

What happens? Did you get three methods generated?

Go ahead and re-run the project and then manually enter the URL suffixes of /store, /store/browse and /store/detail to see the result of this generated code.

Did Copilot recommend any additional methods? If so, would they have been useful?

Additional steps to perform:

  • Use Copilot to make sure you have a Constructor which take one argument of an ILogger. There should be a private property in the class as well that the constructor assigns to.

  • Make sure your StoreController inherits from Controller. You can make this change manually. Your class definition should look like this:

    public class StoreController : Controller

Previous - Home | Next - Securing your code