This short tutorial demonstrates how to create your first D-ASYNC service hosted with ASP NET Core and how to use synchronous HTTP communication.
Using Visual Studio (or the method of your preference), create new empty ASP NET Core application.
Using Visual Studio NuGet Package Manager, add a reference to the Dasync.Fabric.AspNetCore package.
NOTE: make sure to check the "Include prerelease" option, as the D-ASYNC version 2 is in beta at the moment of writing this tutorial.
You can also use the Visual Studio's Package Manager Console:
Install-Package Dasync.Fabric.AspNetCore -ProjectName DasyncTestOr the NET Core CLI:
dotnet add package Dasync.Fabric.AspNetCore
Modify the Startup.cs to include D-ASYNC runtime:
public void ConfigureServices(IServiceCollection services)
{
services.AddDasyncForAspNetCore(model);
}And to use the HTTP handler:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDasync();
}Add a new InventoryService.cs file to the project and implement the class as follows:
public class InventoryService
{
private readonly List<string> _inventory = new List<string>
{
"desk",
"pen",
"mug"
};
// A query.
public virtual async Task<List<string>> GetInventory()
{
return _inventory;
}
// A command.
public virtual async Task AddInventory(string item)
{
_inventory.Add(item);
}
}The added InventoryService class needs to be declared as a D-ASYNC service using a Communication Model. The model allows you to fine tune a service declaration, however, that topic is not covered in this tutorial.
Go back to the Startup.cs and amend the ConfigureServices method:
var model = Dasync.Modeling.CommunicationModelBuilder.Build(_ => _
.Service<InventoryService>(_ => { }));
services.AddDasyncForAspNetCore(model);The project is ready to run, start the application (hit F5 in Visual Studio). By default it opens a browser window with no response from the service.
Modify the URL to invoke the query method by adding /api/Inventory/GetInventory, where /api is the default API path, /Inventory or /InventoryService is the service name, and GetInventory is the method name.
Alternatively, you can use PowerShell:
# PowerShell
# NOTE: set the right port number
Invoke-WebRequest http://localhost:65075/api/Inventory/GetInventoryOr curl:
# bash
# NOTE: set the right port number
curl http://localhost:65075/api/Inventory/GetInventoryOr a GUI tool like Postman.
Executing commands is similar to executing queries, except using the POST method instead of GET. Method names in the URL and input argument names in the request body must match the code.
With PowerShell:
# PowerShell
# NOTE: set the right port number
Invoke-WebRequest -Method 'POST' `
-Headers @{"Content-Type"="application/json"} `
-Body '{ "item": "chair" }' `
-Uri 'http://localhost:65075/api/Inventory/AddInventory'With curl:
# bash
# NOTE: set the right port number
curl -v --request POST \
--header "Content-Type: application/json" \
--data '{ "item": "chair" }' \
http://localhost:65075/api/Inventory/AddInventoryYou can also use a GUI tool like Postman.
- Tutorial 2: Inter-Service Communication
- Tutorial 3: Events and Pub-Sub
- Tutorial 4: Use Asyncrhonous Messages






