CoreCraft.Generators 0.7.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CoreCraft.Generators --version 0.7.0
                    
NuGet\Install-Package CoreCraft.Generators -Version 0.7.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CoreCraft.Generators" Version="0.7.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreCraft.Generators" Version="0.7.0" />
                    
Directory.Packages.props
<PackageReference Include="CoreCraft.Generators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CoreCraft.Generators --version 0.7.0
                    
#r "nuget: CoreCraft.Generators, 0.7.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CoreCraft.Generators@0.7.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CoreCraft.Generators&version=0.7.0
                    
Install as a Cake Addin
#tool nuget:?package=CoreCraft.Generators&version=0.7.0
                    
Install as a Cake Tool

<p align="center"> <img src="images/logo.png" width="15%" /> </p>

build codecov Nuget GitHub

Introduction

CoreCraft is a library that simplifies application state management. With automatic code generation, change tracking, and undo/redo support, you can focus on building robust applications without worrying about managing complex state. Additionally, CoreCraft provides built-in persistence options, allowing you to easily save and load your application's state to a database or file.

Main Features

The CoreCraft provides a wealth of features, including:

  1. Automatic code generation with Roslyn Source Generators: CoreCraft leverages Roslyn Source Generators by automatically generating all necessary entity classes, changes tracking and persistence based on your schema. This automated process eliminates the necessity of manual coding, saving you time and effort.

  2. Change Tracking and Undo/Redo support: CoreCraft implements change tracking mechanisms, allowing you to monitor the application's state modifications. By tracking changes at a granular level, CoreCraft notifies you of specific modifications, enabling you to respond effectively. It provides built-in support for managing and reverting changes, allowing users to undo actions and redo them as needed.

  3. Persistence Options: CoreCraft automatically generates the necessary code to handle persistence (no need to write SQL yourself). It supports saving and loading the application's state to a SQLite database and JSON files.

  4. Reactive Extensions (Rx.NET) Integration: CoreCraft incorporates Reactive Extensions (Rx.NET) to provide a flexible subscription mechanism. It utilizes the IObservable and IObserver interfaces, allowing you to leverage the power of Rx.NET for event-driven programming and reactive data processing.

Benefits

  • Simplify application state management
  • Reduce development time and effort
  • Improve data integrity and consistency

NuGet Packages

CoreCraft is distributed as NuGet packages.

Package Status
CoreCraft Nuget (with prereleases)
CoreCraft.Generators Nuget (with prereleases)
CoreCraft.Storage.SQLite Nuget (with prereleases)
CoreCraft.Storage.Json Nuget (with prereleases)

Getting Started

To start using CoreCraft, follow these steps:

  1. Install CoreCraft and CoreCraft.Generators packages: Run the following command in your terminal or command prompt:
dotnet add package CoreCraft
dotnet add package CoreCraft.Generators
  1. Create a schema file with extension .model.json: Create a new JSON file with the name your_schema.model.json (replace your_schema with your desired schema name). This file will define the structure of your application state.
{
  "shards": [
    {
      "name": "ToDo",
      "entities": [
        {
          "name": "ToDoItem",
          "properties": [
            { "name": "Name", "type": "string", "defaultValue": "string.Empty" }
          ]
        }
      ],
      "collections": [{ "name": "Items", "entityType": "ToDoItem" }],
      "relations": []
    }
  ]
}
  1. Add the schema file to the csproj project file as AdditionalFiles: Open your .csproj file and add the following lines:
<ItemGroup>
  <AdditionalFiles Include="path\to\your_schema.model.json" />
</ItemGroup>

Replace path\to\your_schema.model.json with the actual path to your schema file.

  1. Create an instance of the DomainModel class and register all generated ModelShards: In your code, create an instance of the DomainModel class and register all generated model shards:
var model = new DomainModel([new ToDoModelShard()]);

Example

Here's a example code snippet that demonstrates how to use the CoreCraft:

// Create an instance of the domain model (application state)
var model = new DomainModel([new ToDoModelShard()]);

// Subscribe to Items collection change events
using var subscription = model.For<IToDoChangesFrame>()
    .With(x => x.Items)
    .Subscribe(OnItemChanged);

// Observe changes
void OnItemChanged(Change<ICollectionChangeSet<ToDoItem, ToDoItemProperties>> changes)
{
    foreach (var c in changes.Hunk)
    {
        Console.WriteLine($"Entity [{c.Entity}] has been {c.Action}ed.");
        Console.WriteLine($"   Old data: {c.OldData}");
        Console.WriteLine($"   New data: {c.NewData}");
    }
}

// Adds new item to the collection
await model.Run<IMutableToDoModelShard>(
    (shard, _) => shard.Items.Add(new () { Name = "test" }));

// Saves model to the SQLite database
var storage = new SqliteStorage("my_data.db", []);
await model.Save(storage);

Please refer to the documentation for comprehensive information on using the CoreCraft toolkit and its features.

License

MIT.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.2-preview 126 12/5/2024
0.8.1-preview 104 12/2/2024
0.7.0 224 6/15/2024
0.7.0-preview 96 11/24/2024
0.6.16-preview 126 6/7/2024
0.6.15-preview 94 6/7/2024
0.6.14-preview 99 6/4/2024
0.6.13-preview 103 5/30/2024
0.6.12-preview 112 5/26/2024
0.6.11-preview 143 4/16/2024
0.6.10-preview 185 4/14/2024
0.6.9-preview 141 3/23/2024
0.6.8-preview 133 3/19/2024
0.6.7-preview 157 3/17/2024
0.6.6-preview 179 2/25/2024
0.6.5-preview 171 2/17/2024
0.6.4-preview 133 2/16/2024
0.6.3-preview 136 2/15/2024
0.6.2-preview 121 2/9/2024
0.6.1-preview 213 12/30/2023
0.6.0 284 10/3/2023
0.5.6-preview 225 9/24/2023
0.5.5-preview 226 9/9/2023
0.5.4-preview 205 9/3/2023
0.5.3-preview 196 9/3/2023
0.5.2-preview 204 9/3/2023
0.5.1-preview 284 7/22/2023
0.5.0 202 7/22/2023
0.5.0-preview 309 6/30/2023