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

  • SEARCH
  • Home
  • 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 4100796
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:36:48+00:00 2026-05-20T20:36:48+00:00

I am upgrading a web app from ASP.NET 3 Preview 1 to the RTM

  • 0

I am upgrading a web app from ASP.NET 3 Preview 1 to the RTM and I am confused by the updated approach to dependency injection. I am using StructureMap for this but that’s not really relevant to my question. Previously all I needed to do was as follows:

x.For<IControllerFactory>().Use<DefaultControllerFactory>();
x.For<IServiceLocator>().Use(MvcServiceLocator.Current);

Now it seems like I need to provide implementations of IControllerActivator, IViewPageActivator and ModelMetadataProvider because otherwise I get an error from StructureMap because MVC tries to locate them using the dependency resolver. From a look at the MVC source there do not seem to be public default implementations. Am I missing something in setting these up? Surely these should be configured by convention?

Examples of what needs configuring and how with StructureMap would be appreciated. For reference I am currently using the following ugly kludge which forces MVC to use its internal defaults:

x.For<IControllerFactory>().Use<DefaultControllerFactory>();
x.For<IDependencyResolver>().Use(() => DependencyResolver.Current);                
x.For<IControllerActivator>().Use(() => null);
x.For<IViewPageActivator>().Use(() => null);
x.For<ModelMetadataProvider>().Use(ModelMetadataProviders.Current);

EDIT: Just to be clear I have a working StructureMap implementation of the Dependency Resolver – the issue is why MVC is complaining about all these interfaces not being configured in the container.

  • 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-05-20T20:36:49+00:00Added an answer on May 20, 2026 at 8:36 pm

    I’ve figured this out thanks to the link @Michael Carman posted in a comment on his answer. I’m not sure of the etiquette here as to whether that warrants accepting his actual answer as it wasn’t quite right (I’ve given him +1 vote) but I thought I’d post my own answer to explain exactly what the issue was.

    The problem was down to a combination of my implementation of IDependencyResolver and my container configuration. Originally I had:

    public class StructureMapDependencyResolver : IDependencyResolver
    {
        public object GetService(Type serviceType)
        {
            return ObjectFactory.GetInstance(serviceType);
        }
    
        public IEnumerable<object> GetServices(Type serviceType)
        {
            foreach (object obj in ObjectFactory.GetAllInstances(serviceType))
            {
                yield return obj;
            }
        }
    }
    

    but I have now changed to this based on Steve Smith’s blog post linked to in Jeremy Miller’s blog post:

    public class StructureMapDependencyResolver : IDependencyResolver
    {
        public object GetService(Type serviceType)
        {
            if (serviceType.IsAbstract || serviceType.IsInterface)
            {
                return ObjectFactory.TryGetInstance(serviceType);
            }
            else
            {
                return ObjectFactory.GetInstance(serviceType);
            }
        }
    
        public IEnumerable<object> GetServices(Type serviceType)
        {
            foreach (object obj in ObjectFactory.GetAllInstances(serviceType))
            {
                yield return obj;
            }
        }
    }
    

    on its own this still doesn’t resolve the issue until I remove this configuration expression:

    x.For<IControllerFactory>().Use<DefaultControllerFactory>();
    

    According to the documentation TryGetInstance only returns types registered with the container and will return null if none exist. I presume the MVC 3 code relies on this behaviour to indicate that it should use its defaults, hence in my original case I had to register these defaults with my container. Tricky one!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am uploading files using HttpWebRequest to an ASP.Net MVC application but, for some
I have a web app using thin clients (bosanova terminals) as the front end
We're upgrading an existing program from Win2k/SQL Server 2k to Windows 2003 and SQL
I'm getting a weird error from my sites ever since upgrading to Windows 2008
I have an ASP.NET application that is developed on my laptop and deployed on
After seeing some of the problems that Microsoft has had upgrading people from Internet
Scenario: I have a contact form on my web app, it gets alot of
i'm in the process or upgrading my CI configuration to Web Deployment projects 2010
I have been working on a website using MVC Preview 1 since it came
To facilitate uploading on our web application we install/load an ActiveX control on the

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.