Skip to content

Better options/configuration/control of a Context #136

@Turnerj

Description

@Turnerj

Currently with a context (due to the heavy-ness of MongoDbSet), there is no way to configure things like disable tracking on an entity collection. Even looking at this from the point of view of a MongoDbSet, there is no easy way to achieve this - things are too intertwined.

Take this for example: https://github.com/dansward/DataProtection/blob/c9b4ead5f560fd4ebc1cc27ae6b37e3dbf4f8b0a/samples/EntityFrameworkCore/DataProtectionKeyContext.cs

class DataProtectionKeyContext : DbContext, IDataProtectionKeyContext
{
    public DataProtectionKeyContext(DbContextOptions<DataProtectionKeyContext> options) : base(options) { }
    public DbSet<DataProtectionKey> DataProtectionKeys { get; set; }
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        optionsBuilder.UseInMemoryDatabase("DataProtection_EntityFrameworkCore");
        optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
        optionsBuilder.EnableSensitiveDataLogging();
    }
}

While MongoFramework doesn't have that many things to configure, it provides a nice interface from the point-of-view of a context. There is a way to configure things on a MongoDbSet-level if you override OnDbSetCreation on the context but that isn't particularly nice.

So what do we do? Go the Entity Framework way (which requires refactoring a large portion of our MongoDbSet logic out to the controller and other classes) or try something different?

One thought might be to have something as simple as an OnConfiguring method like EF but instead of moving more stuff to the context, we keep it inside the DbSet.

Alternatively, we could have different types of DbSet's for different things? Some with tracking logic, some without? I mean, we already do this for buckets...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhancements & features

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions