Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
C# 8 and .NET Core 3 Projects Using Azure
C# 8 and .NET Core 3 Projects Using Azure

C# 8 and .NET Core 3 Projects Using Azure: Build professional desktop, mobile, and web applications that meet modern software requirements , Second Edition

Arrow left icon
Profile Icon Michaels Profile Icon Strauss Profile Icon Rademeyer
Arrow right icon
$9.99 $29.99
eBook Dec 2019 528 pages 2nd Edition
eBook
$9.99 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Michaels Profile Icon Strauss Profile Icon Rademeyer
Arrow right icon
$9.99 $29.99
eBook Dec 2019 528 pages 2nd Edition
eBook
$9.99 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

C# 8 and .NET Core 3 Projects Using Azure

Task Bug Logging ASP.NET Core MVC App Using Cosmos DB

In this chapter, we will take a look at using Cosmos DB with ASP.NET Core MVC by creating a task/bug logging application. A personal task manager is useful, and logging bugs is especially handy when you can't attend to them immediately.

We will cover the following topics in this chapter:

  • Setting up a Cosmos DB instance on Azure
  • Scaling and replication features of Cosmos DB
  • Creating an ASP.NET Core MVC application and integrating Cosmos DB

Cosmos DB is Microsoft's rebranding of a document database called DocumentDB. In addition to providing the facilities of a NoSQL database, it also provides a globally scalable solution with virtually no effort.

Technical requirements

Benefits of using Cosmos DB

It's probably worth spending some time exploring why you might choose to use Cosmos rather than one of the myriad other database engines. There are two questions here: why cloud, and why Cosmos specifically?

Why cloud? It's Microsoft's job to scale – not yours

Because Cosmos DB is managed by Microsoft, transitioning to it means that there are suddenly some things that you don't need to worry about. For example, have you ever tried to configure SQL Server to fail over, or what about if you're located in the US and your customers are in Australia? Cosmos handles all these scenarios for you on a pay-as-you-go arrangement. Obviously, if you want your data replicated on...

Setting up Azure Cosmos DB

Throughout this book, we will be using Azure as the cloud provider of choice. If you want to follow along and do not currently have an account, then you can create one at https://azure.microsoft.com/. At the time of writing, you can sign up for free and receive £150/$200 of credits for the first month.

Once you've signed up, visit https://portal.azure.com. Here, you can manage your Azure resources and check your balance.

All cloud providers (at least at the time of writing) have a business model whereby you will get billed for your usage. The fact that you can walk away from your machine does not necessarily mean that any processes that you may have been running in the cloud will stop. This is a very different paradigm from the days when your machine being off meant that nothing was running. At the end of each chapter that uses cloud resources...

Configuring the Cosmos DB instance

Now that the resource is created, we can treat this database instance as though it was MongoDB. To start with, we'll need to launch the Data Explorer:

From here, we can select the following option to create a new collection:

As you can see, I've left the default values here. It's worth noting that Fixed (10 GB) is not the recommended value, and, in a production-grade application, you would very likely want to choose Unlimited. If you do so, then you will need to provide a partition key. I've left the throughput as the default 1000 Request Units per second (RU/s): this effectively allows you to pay for the performance that you need; the slower you go, the cheaper it is (and vice-versa)! Once created, you should be able to see your new collection:

The last thing to do is to navigate to the connection strings tab and copy...

Connecting your ASP.NET Core MVC application to Cosmos DB

When talking about using Cosmos DB in your application, one wonders how easy it will be to add this functionality to a new ASP.NET Core MVC application. The process is really easy. To start off, create a new project:

  1. Name the project BugTracker:
  1. Select the option to create an ASP.NET Core Web Application:
  1. On the next screen, select the following options (referenced in the screenshot below):
  1. Select ASP.NET Core 3.0 from the drop-down list.
  2. Select Web Application (Model-View-Controller).
  3. Uncheck the Enable Docker Support option. Finally, click on the OK button.
  4. Click Create and your new ASP.NET Core MVC application will be created.

Enabling Docker support for your application can easily be done at creation time. You can also enable Docker support for existing applications.

We will take a look at Docker and how...

Reading and writing data to MongoDB

In this section, we will have a look at how to read a list of work items from the MongoDB database and how to insert a new work item into the database (I use the term work item to refer to a task or a bug). This can be done by performing the following steps:

  1. In the Models folder, create a new class called WorkItem, as shown in the following screenshot:
  1. Add the following code to the WorkItem class. You will notice that Id is of the ObjectId type. This represents the unique identifier in the MongoDB document that gets created.
You need to ensure that you add the following using statement to your WorkItem class using MongoDB.Bson;.

Take a look at the following code:

public class WorkItem 
{ 
    public ObjectId Id { get; set; } 
    public string Title { get; set; } 
    public string Description { get; set; } 
    public int Severity { get...

Cleaning up the resources

As mentioned earlier, Microsoft makes their money from Azure based on your usage. In order to avoid incurring costs, you should always clean up (that is, delete) resources that you no longer need. If, like me, you named your Cosmos DB instance bugtracker, then you can return to the Cosmos DB blade (you may have previously pinned this to your dashboard; otherwise, you should search for this) and select the instance.

Then simply select Delete Account:

As with many Azure resources, you have to complete a second step to confirm that you really want to delete the resource:

It may take a few seconds to complete, and after that, you're done.

Summary

There is still so much that you can learn when it comes to Cosmos DB and ASP.NET Core MVC. A single chapter is certainly not enough to cover it all. The days where databases sit on powerful, expensive servers that are housed in a rack in the office that only one guy has the keys to are very much numbered. This can be seen as good and bad: no-one can accidentally unplug or reboot the server, nor will a local power outage have any effect on it; however, you (or your employer) now pay for inefficient queries in pounds and pence (or dollars and cents).

In the next chapter, we will take a look at SignalR on Azure and how to create a real-time chat application.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn the core concepts of web applications, serverless computing, and microservices
  • Create an ASP.NET Core MVC application using controllers, routing, middleware and authentication
  • Build modern applications using cutting-edge services from Microsoft Azure

Description

.NET Core is a general-purpose, modular, cross-platform, and opensource implementation of .NET. The latest release of .NET Core 3 comes with improved performance and security features, along with support for desktop applications. .NET Core 3 is not only useful for new developers looking to start learning the framework, but also for legacy developers interested in migrating their apps. Updated with the latest features and enhancements, this updated second edition is a step-by-step, project-based guide. The book starts with a brief introduction to the key features of C# 8 and .NET Core 3. You'll learn to work with relational data using Entity Framework Core 3, before understanding how to use ASP.NET Core. As you progress, you’ll discover how you can use .NET Core to create cross-platform applications. Later, the book will show you how to upgrade your old WinForms apps to .NET Core 3. The concluding chapters will then help you use SignalR effectively to add real-time functionality to your applications, before demonstrating how to implement MongoDB in your apps. Finally, you'll delve into serverless computing and how to build microservices using Docker and Kubernetes. By the end of this book, you'll be proficient in developing applications using .NET Core 3.

Who is this book for?

This book is for developers and programmers of all levels who want to build real-world projects and explore the new features of .NET Core 3. Developers working on legacy desktop software who are looking to migrate to .NET Core 3 will also find this book useful. Basic knowledge of .NET Core and C# is assumed.

What you will learn

  • Understand how to incorporate the Entity Framework Core 3 to build ASP.NET Core MVC applications
  • Create a real-time chat application using Azure's SignalR service
  • Gain hands-on experience of working with Cosmos DB
  • Develop an Azure Function and interface it with an Azure Logic App
  • Explore user authentication with Identity Server and OAuth2
  • Understand how to use Azure Cognitive Services to add advanced functionalities with minimal code
  • Get to grips with running a .NET Core application with Kubernetes

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 31, 2019
Length: 528 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789610246
Vendor :
Microsoft
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 31, 2019
Length: 528 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789610246
Vendor :
Microsoft
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 180.97
Hands-On Parallel Programming with C# 8 and .NET Core 3
$48.99
C# 8 and .NET Core 3 Projects Using Azure
$43.99
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development
$87.99
Total $ 180.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Ebook Manager and Catalogue App - .NET Core for Desktop Chevron down icon Chevron up icon
Task Bug Logging ASP.NET Core MVC App Using Cosmos DB Chevron down icon Chevron up icon
ASP.NET Azure SignalR Chat Application Chevron down icon Chevron up icon
Web Research Tool with Entity Framework Core Chevron down icon Chevron up icon
Building a Twitter Automated Campaign Manager Using Azure Logic Apps and Functions Chevron down icon Chevron up icon
Stock Checker Using Identity Server and OAuth 2 Chevron down icon Chevron up icon
Building a Photo Storage App Using a Windows Service and Azure Storage Chevron down icon Chevron up icon
A Load-Balanced Order Processing Microservice Using Docker and Azure Kubernetes Service Chevron down icon Chevron up icon
Emotion Detector Mobile App - Using Xamarin Forms and Azure Cognitive Services Chevron down icon Chevron up icon
Eliza for the 21st Century - UWP and the MS Bot Framework Chevron down icon Chevron up icon
WebAssembly Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.