Richard Feich

Rich's Blog

Category: Software Development

Dependency Injection and the Umbraco CMS Platform

On many projects I have used Ninject as my go-to dependency injection framework; it’s open source, flexible,  has good support, and a lot of extensions; but…it’s slow! Daniel Palme did some excellent work comparing the performance of various DI containers; see his results. Here is one of his conclusions supported by data:

Ninject is definitely the slowest container.

With this information I investigated using  the Simple Injector  DI framework. So far, I have used it on ASP.NET Web Forms, MVC, Web API, and console type applications. It’s a great simple super-fast DI framework, and its open source. I recommend trying it out [nuget  package].

Simple Injector is an easy-to-use Dependency Injection (DI) library for .NET 4+ that supports Silverlight, Windows Phone, Windows 8 including Universal apps and Mono. Simple Injector is easily integrated with frameworks such as Web API, MVC,  WCF, ASP.NET Core and many others. It’s easy to implement the dependency injection pattern with loosely coupled components using Simple Injector.”

I have been using Simple Injector in my custom Umbraco projects. Here is how it gets wired-up in the OnApplicationStarted() method:

using SimpleInjector;
using SimpleInjector.Integration.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Mvc;


public class UmbracoEventHandler : IApplicationEventHandler

        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            var appName = ConfigurationManager.AppSettings["ApplicationName"];
            var websiteUrl= ConfigurationManager.AppSettings["WebsiteUrl"];
            var connectionString = ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString;

            var memberRepoParms = new MembershipRepoParms
                ApplicationName = appName,
                WebsiteUrl = websiteUrl,
                ConnectionString = connectionString,
                ApplicationContext = applicationContext

            //Code for registering the repository class and DI
            // 1. Create a new Simple Injector container
            var container = new Container();

            // 2. Configure the container (register)
            container.Register<IMembershipRepository>(() => new MembershipRepository(memberRepoParms));
            container.Register<RenderMvcController>(() => new RenderMvcController());

            // 3. Verify your configuration -- optional

            // MVC Package - These two extension methods from integration package
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));

            // 4. Use the container examples -- this code go in your custom controllers.
            // var repository = container.GetInstance<IMembershipRepository>();
            // var repository = DependencyResolver.Current.GetService<IMembershipRepository>();


File Backup Solution

Problem: I have various files scattered over my entire C-drive (or any drive, folder or library), certain files I would like to backup and organize in someway. It is extremely tedious to click-through folders to find these files. I wrote a utility to automate the process; it’s a console app written in C#. Basically,  I point it to a source drive, I tell it what kind of files I want and  what to paths to ignore, and specify output organization structure…and let it run.

GitHub Repository:
It needs a bit more testing and code clean-up; but it’s functional and I’m using it.

A little bit of setup is required:

  • exclude.txt — contains a list of paths not to scan, for example:
    C:\Program Files
    C:\Program Files (x86)
    C:\Users\Rich\Documents\My Web Sites
    C:\Users\All Users
  • extensions.txt — contains a list of file extensions to look for, for example:
  • App.config settings:
    <add key=”SourceNode” value=”C:\” />
    <add key=”DestinationNode” value=”J:\FileBackup_temp” />
    <add key=”OrganizationFormat” value=”ByYear” />
    <add key=”UseMetadata” value=”true” />

SourceNode: the drive, library, or folder you wish to scan.
DestinationNode: where you wish to copy files to…the destination.
OrganizationFormat:   file organization at the destination, 4 possibilities

Flat — all files in one folder i.e. no hiearchy
ByYear — files organized by year of Create Date  (one level hierarchy)  ex. 2016
ByMonth — files organized by year and month of Create Date (two level hierarchy)  ex. 2016/Oct
ByDay — files organized by year, month, and date  of Create Date (three level hierarchy) ex. 2016/Oct/Oct03

UseMetadatatrue/false,  when set to true the Create Date will be pulled from metada (exif), if it exists. This is useful for digital photography.

I’ll improve this APP as needed for my purposes.

Umbraco CMS Platform

Umbraco is an open source content management system (CMS) platform written in C# built upon Microsoft’s .NET framework using ASP.NET MVC architectural model. Out-of -the-box, Umbraco is not a CMS per se, it’s really a platform for building a CMS; and an excellent one at that. I’ll been using this platform for 10+ years and I must say it has matured into a killer system for building websites and web-based applications. It has great architecture, super extensibility, and a fantastic development ecosystem (support, developers, plugins). Most importantly…the clients love the backoffice for managing content. The backoffice user-experience is fully customizable and components are implemented with AngularJS controllers and views.

To illustrate the power and extensibility of this system I am building a sample project and along the way I’ll explain various techniques and components. I am building an event management system, with grid calendars and event registration. More to come…


  • Hybrid Controllers (SurfaceRenderMvcController, RenderMvcController)
  • Dependency Injection using Simple Injector
  • Data access with Petapoco Micro-ORM and T4 templates
  • Strongly typed content access and views using Umbraco Models Builder
  • Responsive web design with Bootstrap
  • Google Maps integration
  • more…

© 2024 Richard Feich