This repository provides a simple example of a microservice architecture using a Microsoft .NET solution that contains:
- Two microservice (Web API) projects
- One API Gateway project
- Requirements
- Introduction to MariaDB
- Getting started
- Requirements to run the app
- Support and contribution
- License
This sample application will require the following to be installed on your machine:
- .NET 6
- Visual Studio 2022
- MariaDB command-line client (optional), used to connect to and query MariaDB databases.
MariaDB Platform integrates transactional and analytical products so developers can build modern applications by enriching transactions with real-time analytics and historical data, creating insightful experiences and compelling opportunities for customers – and for businesses, endless ways to monetize data.
To get started using MariaDB locally you can choose one of the following options:
SkySQL is the first and only database-as-a-service (DBaaS) to bring the full power of MariaDB Platform to the cloud, including its support for transactional, analytical and hybrid workloads. Built on Kubernetes, and optimized for cloud infrastructure and services, SkySQL combines ease of use and self-service with enterprise reliability and world-class support – everything needed to safely run mission-critical databases in the cloud, and with enterprise governance.
In order to run the TODO application you will need to have a MariaDB instance to connect to. For more information please check out "Get Started with MariaDB".
Download this code directly or use git (through CLI or a client) to retrieve the code using git clone
:
$ git clone https://github.com/mariadb-corporation/dev-example-microservices-dotnet.git
Connect to the database and execute the following SQL scripts using the following options:
1.) Using the MariaDB command-line client to execute the SQL contained within schema.sql.
Example command:
$ mariadb --host HOST_ADDRESS --port PORT_NO --user USER --password PASSWORD < schema.sql
2.) Copying, pasting and executing the scripts contained in schema.sql using a client of your choice.
CREATE DATABASE customer_db;
CREATE TABLE customer_db.`customers` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
CREATE DATABASE product_db;
CREATE TABLE product_db.`products` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`description` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
This application is made of three parts:
- Customers.API - a .NET 6 REST project that uses Entity Framework 6 to connect to and communicate with an underlying MariaDB database.
- Products.API - a .NET 6 REST project that uses Entity Framework 6 to connect to and communicate with an underlying MariaDB database.
- Gateway.API - a .NET project that uses Ocelot to function as an API gateway for the Customers.API and Products.API microservices.
For the Customers.API
and Products.API
microservice projects to use your MariaDB database they must first be configured. The projects already contain connection strings, but depending on your setup you may need to update them.
To do that, update the connection string configuration in the projects' appsettings.json files:
Depending on how you've setup your environment you may have the option to build and run .NET solutions using:
- Visual Studio - build and run the solution by first opening the Demo.sln file using the Visual Studio IDE
- dotnet CLI - build and run the solution by using the dotnet command with the Demo.sln file.
Thanks so much for taking a look at this sample app! As this is a simple example, there's plenty of potential for improvement and customization. Please feel free to submit PR's to the project to include your modifications!
If you have any questions, comments, or would like to contribute to this or future projects like this please reach out to us directly at [email protected] or on Twitter.