Mnemonics.CodingTools 1.0.14

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mnemonics.CodingTools --version 1.0.14
                    
NuGet\Install-Package Mnemonics.CodingTools -Version 1.0.14
                    
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="Mnemonics.CodingTools" Version="1.0.14" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mnemonics.CodingTools" Version="1.0.14" />
                    
Directory.Packages.props
<PackageReference Include="Mnemonics.CodingTools" />
                    
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 Mnemonics.CodingTools --version 1.0.14
                    
#r "nuget: Mnemonics.CodingTools, 1.0.14"
                    
#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 Mnemonics.CodingTools@1.0.14
                    
#: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=Mnemonics.CodingTools&version=1.0.14
                    
Install as a Cake Addin
#tool nuget:?package=Mnemonics.CodingTools&version=1.0.14
                    
Install as a Cake Tool

Mnemonics.CodingTools

License: MIT

Mnemonics.CodingTools is a modular and extensible .NET library for dynamic class generation, runtime entity management, structured logging, and pluggable data storage — built with ASP.NET Core in mind.


✨ Features

  • ⚙️ Dynamic Class Generation
    Generate types at runtime from JSON schemas or programmatic definitions. Compile into assemblies and use immediately.

  • 📚 Runtime Entity Registration (EF Core)
    Register types at runtime via IDynamicTypeRegistry. Automatically used by DynamicDbContext.

  • 💾 Pluggable Entity Stores
    Switch between multiple store implementations via IEntityStore<T> or IAdvancedEntityStore<T>:

    • ✅ In-memory store
    • ✅ File-based (JSON)
    • ✅ EF Core-backed
    • ✅ Dapper-based
      All support composite keys and batch operations (via IAdvancedEntityStore<T>).
  • 🪵 Structured Logging
    Use NinjaLogger as a drop-in structured logger based on Microsoft.Extensions.Logging.

  • 🔌 DI-Ready Architecture
    Register everything with AddCodingTools(). Customize per backend using CodingToolsOptions.


📦 Installation

dotnet add package Mnemonics.CodingTools --version 1.0.x

Or with the NuGet Package Manager:

Install-Package Mnemonics.CodingTools -Version 1.0.x

🚀 Quick Start

Register in Program.cs / Startup.cs

builder.Services.AddCodingTools(options =>
{
    options.RegisterDynamicClassGenerator = true;
    options.RegisterDynamicClassBuilder = true;
    options.RegisterNinjaLogger = true;

    options.RegisterDynamicEFCore = true;
    options.ConfigureDynamicDb = db => db.UseSqlite("Data Source=app.db");
    options.DbContextResolver = sp => sp.GetRequiredService<DynamicDbContext>();

    // Choose one or more entity stores:
    options.RegisterDbStore = true;
    // options.RegisterDapperStore = true;
    // options.RegisterFileStore = true;
    // options.RegisterInMemoryStore = true;

    // (Optional) Custom file store behavior:
    options.FileStoreDirectory = "Data";
    // options.CustomKeySelectors[typeof(MyType)] = (MyType x) => new[] { x.Id.ToString() };
    // options.JsonOptionsPerEntity[typeof(MyType)] = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
});

🧱 Dynamic Class Generation

public class MyService
{
    private readonly IDynamicClassGenerator _generator;

    public MyService(IDynamicClassGenerator generator)
    {
        _generator = generator;
    }

    public void Generate(string json)
    {
        var (dllPath, namespaces) = _generator.GenerateAssemblyFromJson(json, "MyAssembly.dll");
    }
}

🧠 Runtime EF Entity Registration

public class StartupAction
{
    private readonly IDynamicTypeRegistry _registry;

    public StartupAction(IDynamicTypeRegistry registry)
    {
        _registry = registry;
    }

    public void RegisterDynamicType(Type type)
    {
        _registry.RegisterType(type);
    }
}

💾 Generic Entity Store Example

public class EntityService<T> where T : class
{
    private readonly IAdvancedEntityStore<T> _store;

    public EntityService(IAdvancedEntityStore<T> store)
    {
        _store = store;
    }

    public Task SaveAsync(T entity, params string[] keys)
        => _store.SaveAsync(keys, entity);

    public Task<IEnumerable<T>> AllAsync()
        => _store.ListAsync();
}

📁 File Store Example

builder.Services.AddCodingTools(options =>
{
    options.RegisterFileStore = true;
    options.FileStoreDirectory = "EntityStore";
    options.CustomKeySelectors[typeof(MyEntity)] = (MyEntity e) => new[] { e.Id };
});

🪵 Structured Logging with NinjaLogger

public class LogService
{
    private readonly NinjaLogger _logger;

    public LogService(NinjaLogger logger)
    {
        _logger = logger;
    }

    public void LogStuff()
    {
        _logger.Information("This ran at {time}", DateTime.UtcNow);
    }
}

🧾 JSON Schema Example

[
  {
    "Namespace": "Dynamic.Models",
    "Classes": [
      {
        "Name": "User",
        "Properties": [
          { "Name": "Id", "Type": "string" },
          { "Name": "Username", "Type": "string" }
        ]
      }
    ]
  }
]

🧪 Designed for Testing

Interfaces like IDynamicClassGenerator, INinjaLogger, and IAdvancedEntityStore<T> allow for seamless mocking and testing in unit test environments.


🤝 Contributing

Feedback, PRs, and issues are welcome. Fork the repo or file issues at
https://github.com/petervdpas/Mnemonics.CodingTools


📜 License

Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.52 164 4/2/2025
1.0.50 153 4/2/2025
1.0.48 157 4/2/2025
1.0.46 160 4/2/2025
1.0.44 154 4/2/2025
1.0.42 152 4/2/2025
1.0.40 162 4/2/2025
1.0.38 156 4/2/2025
1.0.36 150 4/1/2025
1.0.34 158 4/1/2025
1.0.32 147 3/30/2025
1.0.30 141 3/30/2025
1.0.28 149 3/30/2025
1.0.26 150 3/29/2025
1.0.24 82 3/29/2025
1.0.22 79 3/29/2025
1.0.20 85 3/29/2025
1.0.18 86 3/29/2025
1.0.16 89 3/29/2025
1.0.14 94 3/29/2025
1.0.12 98 3/29/2025
1.0.10 132 3/27/2025
1.0.8 130 3/27/2025
1.0.6 238 3/21/2025