Integrating MVC 4, Entity Framework and Castle Windsor

This is an MVC 4 project demonstrating how to configure Castle Windsor as a dependency injection container. It also demonstrates the use of the repository pattern with Entity Framework 5.


Explore posts in the same categories: ASP .NET MVC, Development


You can comment below, or link to this permanent URL from your own site.

4 Comments on “Integrating MVC 4, Entity Framework and Castle Windsor”

  1. Hi! Thank you for taking time to create and share the code. I downloaded it but I’m having an error:

    The type or namespace name ‘DatabaseModelContainer’ could not be found (are you missing a using directive or an assembly reference?) ModuleInstaller.cs line 37

    • dionscher Says:

      It’s created by Entity Framework and can be found in DatabaseModel.Context.cs:

      public partial class DatabaseModelContainer : DbContext
      public DatabaseModelContainer()
      : base("name=DatabaseModelContainer")

      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      throw new UnintentionalCodeFirstException();

      public DbSet Users { get; set; }

      Are you using EF as a data provider?


  2. Ok, I had unresolved packages and didn’t realize it. Restored all de packages and got I working, thanks.

    BTW, I’m Java Spring developer and I have to create an architecture for a .NET project. Your approach looks very good but I wonder if it really deserves to implement the so called “UnitOfWork” pattern, very popular around IoC .NET architectures. Which are it’s benefits? Is not possible to wrap a group of DB actions in a transaction just using Entinty Framework with Repository pattern?

    • Dion Says:


      Yes it is. A Unit of Work pattern is simply an abstraction/encapsulation around a transactional db operation. However it does also allow you to mock it and therefore promotes easier and effective unit testing.

      Unit of Work or Transaction Block, whatever, you can call it whatever you want. It allows you to decouple your application’s transactional behaviour from the specific implementation of your database.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: