loading...
Turner Software

MiniProfiler ❤ MongoDB

turnerj profile image James Turner Updated on ・2 min read

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 buid.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

MongoFramework

An "Entity Framework"-like interface for MongoDB

AppVeyor 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)
  • 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 mutation (allowing automatic changes on properties during select/insert/update calls)
  • Navigation properties for related entities (both single-entity relationships and collections)
  • Entity Buckets (clustering of small documents together, optimised for write 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.

Extensions

These extensions are official packages that enhance the functionality of MongoFramework, integrating it with other systems and tools.

MongoFramework.Profiling.MiniProfiler

NuGet

Supports profiling database reads…

Posted on by:

turnerj profile

James Turner

@turnerj

Director - Innovator of Things - Co-Author of Your First Year In Code

Turner Software

A small software development company in Adelaide, Australia.

Discussion

pic
Editor guide