This is an ASP.NET Core MVC port of Addy Osmani's Book Library sample for Backbone.js with the following modifications and enhancements:
- The API has been implemented in C# 8 with ASP.NET Core MVC 3.1.
- Unit tests for the API using xUnit.net and Moq have been added.
- Client-side dependencies (i.e. JavaScript and CSS libraries) dependencies are managed with LibMan. The Backbone SPA is bundled and minified using gulp 4. As an alternative to gulp, you can also use BundlerMinifier.Core.
Note that BundlerMinifier.Core doesn't create useful source maps. I recommend using gulp.
- Application Insights is being used for Application Performance Management, including dependency tracking for MongoDB operations.
- Docker Compose and Kubernetes YAML files have been added to run the app on a Docker host or in Kubernetes.
- This project uses MongoDB as database like the original Node.js version. Use whatever flavor of MongoDB works best for you. I recommend using either MongoDB Atlas, Cosmos DB's MongoDB API, or MongoDB 3.6 or newer.
- An Azure Pipeline has been added for CI/CD. This is the pipeline I use to continuously build and deploy this project.
The latest version of this application is deployed at https://booklibrary.joergjooss.de/.
Please make sure to configure your MongoDB connection string in appsettings.json
, as environment variable ConnectionStrings__DefaultConnection
, or in your user secrets.
Requires .NET Core SDK 3.1 or later, Visual Studio 2019 16.4.0 or later, Node.js 12 LTS.
Open BookLibrary-NetCore.sln
and debug or run the solution.
Visual Studio 2019 is the only version of Visual Studio that support .NET Core 3!
Requires .NET Core SDK 3.1 or later, Visual Studio Code 1.40 or later, Node.js 12 LTS.
Open the folder BookLibrary-NetCore
and run the npm: Install Dependencies
, build
and min
tasks, then debug the app or run it from Code's integrated terminal.
Requires .NET Core SDK 3.1 or later, Node.js 12 LTS.
Open a terminal window withyour preferred shell (i.e. PowerShell, bash etc.) and run the following commands:
$ cd \path\to\BookLibrary-NetCore\src\BookLibrary
$ npm install
$ node_modules\.bin\gulp min
$ dotnet run
$ cd /path/to/BookLibrary-NetCore/src/BookLibrary
$ npm install
$ node_modules/.bin/gulp min
$ dotnet run
Launch your web browser and load http://localhost:5000
.
Specify the
--no-launch-profile
option sodotnet
properly honors any environment variable set in your shell. Otherwise, the app will launch with the included Visual Studio 2019 launch profile based onlaunchSettings.json
.
Building a Docker container
Requires Docker Desktop
To build a Docker container directly from the sample's source code, you can use the included Dockerfile. This Dockerfile uses a multi-stage build. Using the included Compose file, the app container will be built on the fly. A prebuilt Docker image for Linux is available at Docker Hub. The Visual Studio solution can also be used to build and debug a container.
Deploying on a Docker host
Please see DOCKE-COMPOSE.md for details how to run the app with Docker Compose.
Deploying on Kubernetes
Please see KUBERNETES.md for details how to run the app in a Kubernetes cluster.
CI/CD with Azure Pipelines
Use the included pipeline .azure/pipelines/ci.yml
to set up your own CI/CD pipeline for this project using Azure Pipelines. This pipeline runs for both pull request validation and full builds of master
, and includes a deployment job for Azure App Services. Pull request validation uses a standard .NET Core SDK build and test, whereas a full build of master runs a multi-stage Docker build. Review the ci.yml
file for further instructions.