-
Notifications
You must be signed in to change notification settings - Fork 3
Lesson 4: A Complete Example
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.
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.
Open up Subscription Manager.sln in your IDE. Build it using Ctrl+Shift+B
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.
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.
Start the Web Application with F5. You should get a browser with an empty JSON array.
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.
Now, we need to tell the loader what files we're going to load into the in-memory database. Double click on the Loader > Data > Index.json file in the Solution Explorer and have a quick look at it. This is a very simple but extensible script that tells the loader where to find the data files and what API verbs and resources are used to import the records. For this step we need to tell the debugger where to find this file.
Right click on the Index.json tab in the editor and chose Copy Full Path. Now, open up the debugger options window by right-clicking on the Loader project in the Solution Explorer pane and selecting Properties... from the drop-down menu. Select the Debug tab on the left hand side, click in the Application arguments edit box and hit Ctrl+V to paste in the name of the index file.
We're now ready to load the data. Build and run the loader with F5. When the program is finished, you'll have an in memory database populated with a realistic set of data. At this point, feel free to experiment. Look at the data in the scripted files, attempt to query resources from the browser, or Get, Delete, Put or Post from Postman.
