<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w" -->

---
title: ASP.NET MVC 3 and MEF sitting in a tree... | daily.dev
description: A walkthrough of implementing dependency injection in ASP.NET MVC 3 preview 1 using the Managed Extensibility Framework (MEF). The post explains the new...
canonical: https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: ASP.NET MVC 3 and MEF sitting in a tree... | daily.dev
og:description: A walkthrough of implementing dependency injection in ASP.NET MVC 3 preview 1 using the Managed Extensibility Framework (MEF). The post explains the new...
og:url: https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w
og:image: https://api.daily.dev/og/posts/3v6kAoY7W.png
og:image:alt: ASP.NET MVC 3 and MEF sitting in a tree...
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# ASP.NET MVC 3 and MEF sitting in a tree...

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 7 min read · 0 upvotes · 0 comments

## Summary

A walkthrough of implementing dependency injection in ASP.NET MVC 3 preview 1 using the Managed Extensibility Framework (MEF). The post explains the new IServiceLocator-based DI hooks introduced in MVC 3 (controller factories, controller creation, view creation, action filters) and shows full code for a custom ServiceLocatorControllerFactory and MefServiceLocator that compose controllers and views via MEF, with a fallback to the default locator for framework services not exported via MEF. Sample code is provided for download.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2010-07-27-aspnet-mvc-3-and-mef-sitting-in-a-tree>

## Questions this post answers

### How do I set up dependency injection in ASP.NET MVC 3 using the new IServiceLocator?

Register an IServiceLocator implementation in Global.asax with a single call: MvcServiceLocator.SetCurrent(new SomeServiceLocator()). This makes dependency injection work automatically across controllers, action filters, and views, since ASP.NET MVC 3 preview 1 routes its four new DI hooks (controller factories, controllers, views, action filters) through the Common Service Locator's IServiceLocator interface.

_daily.dev surfaces practical deep dives like this for developers wiring DI into ASP.NET MVC._

### How can I use MEF (Managed Extensibility Framework) to compose controllers and views in ASP.NET MVC?

Build a custom IMvcServiceLocator backed by a MEF CompositionContainer, plus a ServiceLocatorControllerFactory that resolves controllers through that locator instead of DefaultControllerFactory. Export controller types with [Export], use a per-request container with an application-wide catalog, and fall back to the default MVC service locator for framework types like IFilterProvider that aren't MEF-exported.

_developers piecing together MEF-based composition can find similar in-depth examples on daily.dev._

## Similar posts on daily.dev

- [12 Rules for Dependency Injection in ASP.NET Core](https://daily.dev/posts/12-rules-for-dependency-injection-in-asp-net-core-nirfrs5ef) · We Are .NET · 3 upvotes · 1 comments
- [How to Migrate from ASP.NET Framework to ASP.NET Core](https://daily.dev/posts/how-to-migrate-from-asp-net-framework-to-asp-net-core-e22ntd3va) · freeCodeCamp · 4 upvotes · 0 comments
- [ASP.NET, Factory Patterns, and the Illusion of Control](https://daily.dev/posts/asp-net-factory-patterns-and-the-illusion-of-control-up6aoiahc) · We Are .NET · 3 upvotes · 0 comments
- [How to Upgrade ASP.NET MVC to .NET Step by Step](https://daily.dev/posts/how-to-upgrade-asp-net-mvc-to-net-step-by-step-i3p1uesfs) · C\# Corner · 2 upvotes · 0 comments

---

Tags: [#aspnet](https://daily.dev/tags/aspnet), [#c#](https://daily.dev/tags/c#), [#dependency-injection](https://daily.dev/tags/dependency-injection)

[View this post on daily.dev](https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"ASP.NET MVC 3 and MEF sitting in a tree...","url":"https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w"},"datePublished":"2026-10-04T13:05:57.405Z","dateModified":"2026-10-15T02:22:30.608Z","description":"A walkthrough of implementing dependency injection in ASP.NET MVC 3 preview 1 using the Managed Extensibility Framework (MEF). The post explains the new...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/53254afd7233a68e44999b733756f496?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/53254afd7233a68e44999b733756f496?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"aspnet,c#,dependency-injection","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"ASP.NET MVC 3 and MEF sitting in a tree..."}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/asp-net-mvc-3-and-mef-sitting-in-a-tree--3v6kaoy7w#faq","mainEntity":[{"@type":"Question","name":"How do I set up dependency injection in ASP.NET MVC 3 using the new IServiceLocator?","acceptedAnswer":{"@type":"Answer","text":"Register an IServiceLocator implementation in Global.asax with a single call: MvcServiceLocator.SetCurrent(new SomeServiceLocator()). This makes dependency injection work automatically across controllers, action filters, and views, since ASP.NET MVC 3 preview 1 routes its four new DI hooks (controller factories, controllers, views, action filters) through the Common Service Locator's IServiceLocator interface. daily.dev surfaces practical deep dives like this for developers wiring DI into ASP.NET MVC."}},{"@type":"Question","name":"How can I use MEF (Managed Extensibility Framework) to compose controllers and views in ASP.NET MVC?","acceptedAnswer":{"@type":"Answer","text":"Build a custom IMvcServiceLocator backed by a MEF CompositionContainer, plus a ServiceLocatorControllerFactory that resolves controllers through that locator instead of DefaultControllerFactory. Export controller types with [Export], use a per-request container with an application-wide catalog, and fall back to the default MVC service locator for framework types like IFilterProvider that aren't MEF-exported. developers piecing together MEF-based composition can find similar in-depth examples on daily.dev."}}]}
```

