Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8319629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:23:04+00:00 2026-06-08T22:23:04+00:00

I have an MVC3 web application where controllers use services to perform certain tasks.

  • 0

I have an MVC3 web application where controllers use services to perform certain tasks.
I use to instantiate the needed services in each action separately,like so for example:

 public ActionResult Index()
    {
        ICustomService customService = new CustomService();
        var list = customService.ReturnSomething();
        .....
        return View(list)
    }

This was working fine. Then I decided to use MEF for dependecy injection in order to follow better design principles. So now I’m doing something like this:

   public class MyController : Controller
   {
    [Import]
    private ICustomService _customService;

    public MyController()
    {
        MEFManager.Compose(this);
    }

    public ActionResult Index()
    {
      var list = _customService.ReturnSomething();
      return View(list);
    }

Where Composition is done by MEFManage.Compose(this) which is the following function:

    public static void Compose(object o)
    {
        var container = new CompositionContainer(
                                                new DirectoryCatalog(Path.Combine(
                                                                       AppDomain.CurrentDomain.BaseDirectory, "bin"))
                                                                    );
        var batch = new CompositionBatch();
        batch.AddPart(o);
        container.Compose(batch);
    }

This actually WORKS but it is 6 to 7 times slower than when I wasn’t using MEF.
Does anyone know why it is so slow? I am doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:23:06+00:00Added an answer on June 8, 2026 at 10:23 pm

    Spinning up a CompositionContainer is not a resource intensive task, but, creating a DirectoryCatalog is, it has to scan all available assemblies to identify parts and analyse the composition elements for exports. You could improve this a number of ways:

    1. You could have a singular DirectoryCatalog (or preferably a ComposablePartCatalog) that all your containers use when constructing, this means that the catalog creation is only done once.
    2. You could avoid container creation in your constructor entirely and implement either an IControllerFactory to spin up your controller instances, or an IDependencyResolver to handle dependency resolution using MVC3’s built in service location mechanism. There are many examples on the web if you search for MEF + MVC.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple MVC3 Web application. I use structureMap as a dependency Injection.
i have created an mvc3 web application that uses forms based authentication. one part
I have written an ASP.NET MVC3 Web application which runs perfectly inside the Visual
This is about asp.net mvc3 web application. We have used Object cache to store
I am working on a web application (asp.net mvc3) I have a Main div.
I am using AJAX-enable web services in my ASP.NET MVC3 application and I want
I have an MVC3 application and in one of my actions in my controllers
Im working on a big MVC3 web application and have an annoyance regarding the
I have an ASP.NET MVC3 web application with C# and Razor. Through a form
I am currently creating an MVC3 application using Ninject. I have two controllers which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.