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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:20:57+00:00 2026-05-26T15:20:57+00:00

I’m working on a large Asp.Net MVC3 application (>50 views) and we are currently

  • 0

I’m working on a large Asp.Net MVC3 application (>50 views) and we are currently planning on using Unity for our dependency injection framework. For ease of maintenance, I would like to be able to query the assembly to find all of the base types, then register them with Unity.

Based on sample code from the Unity MVC3 Project for registering all controllers, I tried the following code –

var orchestratorTypes = (from t in Assembly.GetCallingAssembly().GetTypes()
                        where typeof(IOrchesratorBase).IsAssignableFrom(t) &&
                        !t.IsAbstract
                        select t).ToList();
orchestratorTypes.ForEach(t => container.RegisterType(t);

When I run the application I get the following error message

The current type, WwpMvcHelpers.BaseClasses.IOrchesratorBase, is an interface and cannot be constructed. Are you missing a type mapping?

If I register the class using individually, as below –

container.RegisterType<IOrchesratorBase, HomeOrchestrator>();

Everything works correctly. Is there a way to do this so that I don’t have to register each type individually?

EDIT

Per request, my inheritance hierarchy is

HomeOrcestrator <- IOrchesratorBaseList<LocalModel>
                <- OrchesratorBase<LocalModel> <- IOrchesratorBase

The usage in the controller is

public class HomeController : ControllerListBase <HomeOrchestrator, LocalModel>
{
    public HomeController() {}
    public HomeController(IOrchesratorBase homeOrchestrator) {
        this.Orchestrator = (HomeOrchestrator) homeOrchestrator;
    }
  • 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-26T15:20:58+00:00Added an answer on May 26, 2026 at 3:20 pm

    The LINQ to get the types appears to work. I don’t think that’s your problem.

    You’ll get a similar error if you just write

    container.RegisterType(typeof(HomeOrchestrator));
    

    and call container.Resolve<IOrchesratorBase>().

    In other words, RegisterType(t) is not the same as RegisterType<I, T>().

    The real question is, what are you resolving and how do you want it resolved? Your query is finding implementors of IOrchesratorBase. Are your injection constructor parameters of that type? If so, what’s Unity supposed to do when 20 types implement that interface?

    Can you provide more information on your class/interface hierarchy, constructor parameters, and what you expect/want to happen?

    (I’d refactor to change IOrchesratorBase to IOrchestratorBase, BTW.) 🙂

    Edit

    Based on the edited question, the problem is that, in order to resolve a HomeController, Unity is looking for a type registration for IOrchesratorBase. It determines the interface type by the parameter types of the constructor with the most parameters.

    If you write container.RegisterType<IOrchesratorBase, HomeOrchestrator>() the answer is obvious – Unity will construct an instance of HomeOrchestrator and inject it.

    Now, is there more than one type that implements IOrchesratorBase? If so, and you register both of them (explicitly), Unity will use whichever one you register last. That may not be what you want.

    If you have multiple controllers, each taking a different interface type in their constructors (with only one implementation per interface), you’ll need to figure out what each interface type is and re-run your LINQ registration for each one. That could be done via reflection – find the orchestrators or the controllers.

    If you have multiple controllers, each taking the same interface type in their constructors and you want different implementations for each, you’ve got a problem. You’d have to register named types and determine the names somehow, or something similar.

    Unity isn’t magic. It can’t figure out your intentions.

    Addendum

    Unity can operate in a convention-over-configuration mode; see Using Unity With Minimal Configuration.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to

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.