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 6558701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:13:55+00:00 2026-05-25T13:13:55+00:00

I am using the mvc 3 framework of asp.net, I have created a UnityControllerFactory

  • 0

I am using the mvc 3 framework of asp.net, I have created a UnityControllerFactory that implements the IControllerFactory interface:

...
public class UnityControllerFactory : IControllerFactory
{
    private IUnityContainer _container;
    private IControllerFactory _innerFactory;

    public UnityControllerFactory(IUnityContainer container)
        : this(container, new DefaultControllerFactory())
    {
    }

    protected UnityControllerFactory(IUnityContainer container,
                                     IControllerFactory innerFactory)
    {
        _container = container;
        _innerFactory = innerFactory;
    }
public IController CreateController(RequestContext requestContext,
                                        string controllerName)
    {
        try
        {
            IController controller = _container.Resolve<IController>(controllerName.ToLowerInvariant);

            return controller;
        }
        catch (Exception ex)
        {
            var msg = ex.Message;
            return _innerFactory.CreateController(requestContext, controllerName);
        }

    }
...

and in the Application_Start(), I have:

protected void Application_Start() {
        AreaRegistration.RegisterAllAreas();
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);


        IUnityContainer container = GetUnityContainer();
        container.RegisterType<IRepository<User>, LiveRepository<User>>();
        DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory(container));
        ...

    }

I test this with a home controller

public class HomeController : Controller{
    IRepository<User> userRepo;
    public HomeController(IRepository<User> userRepo)
    {
         this.userRepo = userRepo;
    }
    ...
}

When I run the app, I can not build the home controller at all.
in the line:

IController controller = _container.Resolve<IController>(controllerName.ToLowerInvariant);

I get an exception says:

**”Resolution of the dependency failed, type = “System.Web.Mvc.IController”, name =
“homecontroller”. Exception occurred while: while resolving.

Exception is: InvalidOperationException – The current type, System.Web.Mvc.IController, is an interface and cannot be constructed. Are you missing a type mapping?

At the time of the exception, the container was: Resolving System.Web.Mvc.IController,homecontroller”**

but even with the default controller factory using the line:

_innerFactory.CreateController(requestContext, controllerName);

I still cannot build the controller at all, please help

  • 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-25T13:13:55+00:00Added an answer on May 25, 2026 at 1:13 pm

    I would recommend you taking a look at the following blog post which illustrates how to use a custom DependencyResolver with Unity in an ASP.NET MVC 3 application.

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

Sidebar

Related Questions

I am using the asp.net mvc with the Entity Framework. I have a list
I am fairly new at using the ASP.NET MVC framework and was hoping that
I am converting an application I created using webforms to the asp.net mvc framework
I have a pretty big web application that I created last year using ASP.NET
I'm building an ASP.NET MVC site using the ADO.NET Entity Framework. I have an
I have just started playing with the ASP.Net MVC framework, and today I created
I have an ASP.NET MVC 3 app that is using SQL Server CE 4.0
I have an existing website developped using ASP.NET MVC 3 and Entity Framework 4
I have created a new ASP.NET MVC project using the MVC Project Template. According
I have already built my web pages using jQueryMobile and ASP.NET MVC framework. Now,

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.