Let's go ahead and add a new Controller using Copilot!
-
Select the
Controllers
folder in your Solution Explorer and then hit Ctrl+Shift+A -
In the dialog box name the file
StoreController.cs
-
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