Aiursoft.DbTools.InMemory 9.0.13

DBTools

MIT licensed Pipeline stat Test Coverage NuGet version (Aiursoft.CSTools) ManHours

DbTools are Aiursoft's common database tools. It simplifies the process of registering DbContext and updating database. So your application can easily switch from different database types without editing the code.

How to install

Run the following command to install Aiursoft.DbTools.Switchable to your ASP.NET Core project from nuget.org:

dotnet add package Aiursoft.DbTools.Switchable

Run the following command to install Aiursoft.DbTools.InMemory to your database implementation project from nuget.org:

dotnet add package Aiursoft.DbTools.InMemory

All database implementation projects must reference a single AbstractDb project. And you need to define and use the abstract class YourDbContext in it.

Make sure your project dependency is as follows:

---
title: Project dependency diagram
---

stateDiagram-v2
    Aiursoft.DbTools.InMemory --> Aiursoft.DbTools
    Aiursoft.DbTools.Sqlite --> Aiursoft.DbTools
    Aiursoft.DbTools.MySql --> Aiursoft.DbTools
    Aiursoft.DbTools.Switchable --> Aiursoft.DbTools
    Demo.Entities --> Aiursoft.DbTools
    Demo.Sqlite --> Aiursoft.DbTools.Sqlite
    Demo.Sqlite --> Demo.Entities
    Demo.MySql --> Aiursoft.DbTools.MySql
    Demo.MySql --> Demo.Entities
    Demo.InMemory --> Aiursoft.DbTools.InMemory
    Demo.InMemory --> Demo.Entities
    Demo.WebApp --> Aiursoft.DbTools.Switchable
    Demo.WebApp --> Demo.InMemory
    Demo.WebApp --> Demo.MySql
    Demo.WebApp --> Demo.Sqlite
    Aiursoft.DbTools.SqlServer --> Aiursoft.DbTools

Usage

In your startup.cs:

// In your Web project
public void ConfigureServices(IConfiguration configuration, IWebHostEnvironment environment, IServiceCollection services)
{
    var (connectionString, dbType, allowCache) = configuration.GetDbSettings();
    services.AddSwitchableRelationalDatabase(
        dbType: EntryExtends.IsInUnitTests() ? "InMemory": dbType,
        connectionString: connectionString,
        supportedDbs:
        [
            // These comes from your database implementation projects.
            new MySqlSupportedDb(allowCache: allowCache, splitQuery: false),
            new SqliteSupportedDb(allowCache: allowCache, splitQuery: true),
            new InMemorySupportedDb()
        ]);

    services
        .AddControllersWithViews()
        .AddApplicationPart(typeof(Startup).Assembly);
}

In your appsettings.json:

{
    "ConnectionStrings": {
        "AllowCache": "True",
        "DbType": "Sqlite",
        "DefaultConnection": "DataSource=app.db;Cache=Shared"
    }
}

Or:

{
  // sudo docker run -d --name db -e MYSQL_RANDOM_ROOT_PASSWORD=true -e MYSQL_DATABASE=kahla -e MYSQL_USER=kahla -e MYSQL_PASSWORD=kahla_password -p 3306:3306 hub.aiursoft.cn/mysql
  "ConnectionStrings": {
    "AllowCache": "True",
    "DbType": "MySql",
    "DefaultConnection": "Server=localhost;Database=kahla;Uid=kahla;Pwd=kahla_password;"
  }
}

Or:

{
  "ConnectionStrings": {
    "AllowCache": "False",
    "DbType": "InMemory"
  }
}

Simple, isn't it?

Your database project need to be different with your web project, you need the following command to generate migrations:

cd ./Demo.MySql
dotnet ef migrations add Init --context "MySqlContext" -s ../Demo.WebApp/Demo.WebApp.csproj
cd ..

cd ./Demo.Sqlite
dotnet ef migrations add Init --context "SqliteContext" -s ../Demo.WebApp/Demo.WebApp.csproj
cd ..

For more usage, please check the Demo app in the demos folder!

How to contribute

There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.

We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.

Showing the top 20 packages that depend on Aiursoft.DbTools.InMemory.

Packages
Aiursoft.BaGet.Database.InMemory
Package Description
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
Aiursoft.GptGateway.InMemory
Package Description
Aiursoft.SDK
The base class, tools and extends for Aiursoft web apps.

Version Last updated
9.0.13 04/09/2025
9.0.12 03/12/2025
9.0.11 03/12/2025
9.0.4 03/18/2025
9.0.3 03/15/2025
9.0.2 03/15/2025
9.0.1 01/16/2025
9.0.0 12/30/2024
8.0.13 11/13/2024
8.0.12 10/15/2024
8.0.11 03/27/2025
8.0.10 04/08/2025
8.0.9 04/20/2025
8.0.8 03/31/2025
8.0.7 04/21/2025
8.0.6 04/14/2025
8.0.5 05/16/2024
8.0.4 05/04/2024
8.0.3 03/17/2024
8.0.2 03/17/2024
8.0.1 02/25/2024
8.0.0 04/07/2025
7.0.19 02/14/2024
7.0.18 02/04/2024
7.0.17 02/02/2024
7.0.16 03/28/2025
7.0.15 01/30/2024
7.0.14 03/25/2025
7.0.13 04/12/2025
7.0.12 03/12/2025
7.0.11 12/24/2023
7.0.10 04/09/2025
7.0.9 11/26/2023
7.0.8 03/26/2025
7.0.7 04/01/2025
7.0.6 11/02/2023
7.0.5 04/07/2025
7.0.4 10/31/2023
7.0.3 10/27/2023
7.0.2 04/20/2025
7.0.1 04/09/2025
7.0.0 09/05/2023
6.0.32 04/02/2025
6.0.31 03/20/2025
6.0.30 03/28/2025
6.0.29 03/30/2025