DEV Community

James Turner for Turner Software

Posted on • Edited on • Originally published at turnerj.com

MiniProfiler ❤ MongoDB

If you're familiar with .NET, you may have heard of an awesome project called MiniProfiler made by the awesome folks at Stack Overflow.

GitHub logo MiniProfiler / dotnet

A simple but effective mini-profiler for ASP.NET (and Core) websites

MiniProfiler for .NET (and .NET Core)

Welcome to MiniProfiler for .NET, ASP.NET, ASP.NET Core, ASP.NET MVC and generally all the combinations of those words. Documentation for MiniProfiler for .NET is in /docs, accessible via GitHub pages at: miniprofiler.com/dotnet. General information for MiniProfiler across platforms can be found at miniprofiler.com. It is part of the .NET Foundation, and operates under their code of conduct.

AppVeyor Build Status Actions Build

The current major version of MiniProfiler is v4.

Handy Links

Building

To build the MiniProfiler solution in Visual Studio, you'll need:

  • Visual Studio 2019 16.3+ (or the .NET Core 3.x SDK)
  • The Web Compiler extension
    • Note: no extension is needed if building via build.cmd or build.ps1

If you're unfamiliar, you may have gathered from the name it has something to do with profiling code - you wouldn't be wrong!

MiniProfiler isn't designed to profile every method call - it is however designed to profile the calls you specifically want to know about. These include things like database calls, your controllers or your views. You can optionally profile any other code you want through MiniProfiler's API.

MongoDB - some love it, some hate it but regardless I use it and I like it for my projects. What I don't like with MongoDB is the C# driver so as an ongoing project of mine, I have built my own wrapper for MongoDB C# driver called MongoFramework. I have written about this library previously here so I won't go into much detail besides saying it makes dealing with MongoDB similar to dealing with Entity Framework.

MongoFramework however is how MiniProfiler and MongoDB meet. You see, MiniProfiler has official packages for profiling EF6 and EF Core but doesn't actually support profiling of MongoDB queries. As I had already written a wrapper around the official MongoDB driver, I was already in a good place to extend my own integration to support profiling.

MongoFramework uses a diagnostic layer inspired by how MiniProfiler actually connects into EF Core. This diagnostic layer is per connection for MongoFramework and as an interface, can easily be swapped out for any other diagnostic tool. The diagnostic layer is invoked at every entity read/write as well as the creation of indexes.

MiniProfiler profiling dialog showing a MongoDB column

MiniProfiler showing an actual MongoDB query

So if you:

  • are building a project in .NET
  • are using MongoDB for persistence via MongoFramework
  • are using or want to use MiniProfiler

Then this might be exactly what you are looking for! Check it out on NuGet.

GitHub logo TurnerSoftware / MongoFramework

An "Entity Framework"-like interface for MongoDB

Icon

MongoFramework

An "Entity Framework"-like interface for MongoDB

Build Codecov NuGet Codacy Badge

Overview

MongoFramework tries to bring some of the nice features from Entity Framework into the world of MongoDB.

Some of the major features include:

  • Entity mapping for collections, IDs and properties through attributes
  • Indexing through attributes (including text and geospatial)
  • Fluent mapping builder
  • Entity change tracking
  • Changeset support (allowing for queuing multiple DB updates to run at once)
  • Diff-updates (only changes to an entity to be written)
  • Entity Buckets (clustering of small documents together, improving index performance)
  • Runtime type discovery (serialize and deserialize without needing to specify every "known" type)

MongoFramework is currently built on-top of the official MongoDB C# driver.

Licensing and Support

MongoFramework is licensed under the MIT license. It is free to use in personal and commercial projects.

There are support plans available that cover all active Turner Software OSS projects Support plans provide private email support, expert…

Top comments (0)