Skip to content

Lesson 4: A Complete Example

Donald Roy Airey edited this page Feb 7, 2019 · 8 revisions

We've learned the basics of creating a data model from an XML Schema (XSD) description. We've also learned how to resolve parent key elements using a symbolic lookup. In this lesson we're going to build a real-life write-through cache using a cloned project from GITHUB.

Step 1

Go to the location on your disk where you store your source files and type

git clone https://github.com/GammaFour/subscription-manager.git

In this directory you'll find two solutions: Subscription Manager.sln is a complete Web Application with a RESTful API and a write-through cache. Loader.sln is a simple program to import the scripted data that you might create for a test-driven design (TDD). The data in this project will illustrate some of the key points of the generated REST API.

Step 2

Open up Subscription Manager.sln in your IDE. Build it using Ctrl+Shift+B

Step 3

For this step you'll need access to either an SQL Server Database or a PostgreSQL Database. In the Web Application project, open up the appsettings.Development.json file by double-clicking it. You should see:

{
  "DbProvider": "SqlServer",
  "ConnectionStrings": {
    "SqlServerConnection": "Data Source=localhost;Initial Catalog='Subscription Manager';Integrated Security=True",
    "PostgreSqlConnection": "Server=localhost;Database=investment_management;Port=5432;User Id=postgres;Password=password"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

Select either SqlServer or PostgreSql for the DbProvider and update the connection string for your environment. Save your changes with Ctrl+S.

Step 4

Navigate to the Package Manager Console using Tools > NuGet Package Manager > Package Manager Console. In the Package Manager Console, type:

Add-Migration InitialMigration

This will generate a script for creating the database through Entity Framework.

Update-Database

Will commit those changes to the database you selected in Step 3.

Step 5

Start the Web Application with F5. You should get a browser with an empty JSON array.

Step 6

Go back to your file explorer or source code directory and open the Loader.sln project.

Open the appsettings.json file. It should look like:

{
  "host": "https://localhost:44371/"
}

Verify that this is the host and port in the browser that was started in Step 5. The loader will attempt to use the REST API that it finds at this base URL address.

Step 7

Build and run the loader with F5.

Clone this wiki locally