Sample Server
A sample datasync server
Our sample datasync server provides an “Azure Developer CLI” ready implementation of the TodoItems service required by our TodoApp client samples. It uses Azure SQL as its backend.
Deploying the sample datasync server
Download the sample server from our GitHub repository.
Sign in to Azure using the Azure Developer CLI:
azd auth login
This will open up a browser. If you encounter difficulties, refer to the Azure Developer CLI documentation.
Run the
azd up
command:azd up
This will take approximately 5-15 minutes to deploy. At the end of the process, you will be provided with the URL to your datasync service. Record this URL for later use.
Decommissioning the datasync server
You can easily decommission the datasync server using azd down
. This will remove all resources that were created by azd up
.
The code
Start with the Program.cs
file:
|
|
The lines that are highlighted are those added for the datasync service:
- Line 1 brings in the correct package.
- Line 11 adds datasync functionality to the services collection.
Next, the model:
|
|
- Line 1, again, brings in support for the datasync repository; specifically the
EntityTableData
class. - Line 6 ensures the model inherits from
EntityTableData
so that the correct properties are defined.
Our DbContext
is simple:
|
|
You can (and should) use migrations instead of EnsureCreatedAsync()
to create your database.
This is because the standard EntityTableData
has attributes to correctly update the UpdatedAt
and Version
properties so you don’t have to worry about this detail. Finally, we have one controller:
|
|
In many respects, this datasync server is a standard ASP.NET Core Web API controller with minimal changes to support datasync services.