DocumentFramework.Tool 0.1.1-alpha

This is a prerelease version of DocumentFramework.Tool.
dotnet tool install --global DocumentFramework.Tool --version 0.1.1-alpha
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local DocumentFramework.Tool --version 0.1.1-alpha
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=DocumentFramework.Tool&version=0.1.1-alpha&prerelease
nuke :add-package DocumentFramework.Tool --version 0.1.1-alpha

Document Framework

.NET Package .NET Tool Nuget

A light weight ORM for mongo and dotnet.

Notable features

  • EF style registration and usage
  • Migrations

Usage

  1. Add a model
public class Foo
{
  [BsonId]
  [BsonRepresentation(BsonType.ObjectId)]
  public string Id { get; set; }
  public string Text { get; set; }
}
  1. Create a MongoContext
dotnet df dbcontext scaffold -c BarMongoContext
  1. Add a collection for your model to you MongoContext
public class BarMongoContext : MongoContext
{
  public readonly IMongoCollection<Foo> Foos;

  public BarMongoContext(IMongoDatabase database, IEnumerable<IMongoMigration> migrations, ILogger<MongoContext> logger)
    : base(migrations, database, logger)
  {
    Foos = GetOrAddCollection<Foo>("foos"); // Add this line in you generated mongo context
  }
}
  1. Create a migration
dotnet df migrations add SeedFoos
  1. Implement the MigrationForward and MigrateBackward methods in your new migration
public class SeedFoos : IMongoMigration
{
  public string MigrationName => "20210420000000_SeedFoos";
  private readonly IMongoDatabase _database;

  public SeedFoos(IMongoDatabase database)
  {
    _database = database;
  }

  public void MigrateForward()
  {
    var fooCollection = _database.GetCollection<Foo>("foos");

    fooCollection.InsertMany(new Foo[] { 
        new Foo { Text = "document-1" }, 
        new Foo { Text = "document-2" }
    });
  }

  public void MigrateBackward()
  {
    throw new NotImplementedException();
  }
}
  1. Register Context and mongo database in the ConfigureServices method in your Startup.cs
services
    .AddMongoContext<BarMongoContext>()
    .AddTransient<IMongoDatabase>()
  1. Sync migrations in the Configure method in your Startup.cs
app.ApplicationServices
        .GetRequiredService<BarMongoContext>()
        .SyncMigrations();
  1. Use the Mongo context to query collections
public class SomeService
{
    private readonly BarMongoContext _context;

    public SomeService(BarMongoContext context)
    {
        _context = context;
    }

    public IEnumerable<Foo> GetSomeFooStuff(string text) 
    {
        _context.Foos.Find(f => f.Text == text).ToEnumerable();
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.1.1-alpha 170 10/26/2021
0.1.0-alpha 148 10/26/2021