I've done an initial conversion of my Task and Await sample code to .NET Core 2.0. I'll be describing the conversion, projects, and code in a future article. But I wanted to put the code out there for the curious since the GitHub projects have been created.
Web API project: https://github.com/jeremybytes/person-api-core
Console application: https://github.com/jeremybytes/task-app-core
If you're really curious (and already have .NET Core installed/working in your environment), you can get the projects from GitHub.
Note: .NET Core 2.0 Articles are collected here: Getting Started with .NET Core 2.0.
The Person API
The console application uses a JSON service that returns Person objects. The service is in the person-api-core project. To run this, download the code and navigate to the folder in the terminal/console (or open the folder in Visual Studio code and use the integrated Terminal window).
Typing "dotnet run" will start the WebAPI service:
The default location is "http://localhost:9874".
Navigating to "http://localhost:9874/api/people" will produce the following result:
This is the data that is consumed by the console application in the other project. You'll need to leave this API running for the console application to work.
Update: I wrote an article that describes the creation of this service: Building a WebAPI Service With .NET Core 2.0.
The Console Application
The console application consumes the API and has a bit of asynchronous code using Task. I'll be updating this code in the future to show various functionality including cancellation, exceptions, and progress reporting.
In the meantime, you can get the code from the task-app-core project. Download the code, and navigate to the folder in a new terminal/console (different from the one running the API project) or by opening the folder in another instance of Visual Studio Code.
Just type "dotnet run" to kick things off:
This will print out "One Moment Please" and then pause for 3 seconds waiting for the asynchronous operation to complete. After the pause, it will print out a list of names.
Press "Return" to exit the console application.
Update: I wrote an article that describes the creation of the console application, including how to bring in a NuGet package: Consuming a WebAPI Service with .NET Core 2.0.
Note: As expected, the code runs just as well under Windows 10. Here are the same screens in PowerShell after downloading the projects from GitHub:
More to Come
If you're curious at this point, you can take a look at the code. I'll be posting some articles in the future showing how I created the projects and moved my code over from the full framework solution.
The most interesting part is that I've been doing all of this development in macOS using Visual Studio Code and a bash terminal.
I do miss having XAML and a cool UI for the demo code (yeah, I know I could use Xamarin, but I'm not there quite yet). But I think we'll be able to see the same concepts with a bit more tweaking to the console application(s).
I've been having a good time exploring. There are a few quirks about the environment that bother me, but they're also probably things that I'll just have to get used to.
Happy Coding!
great
ReplyDelete