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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:21:34+00:00 2026-06-03T17:21:34+00:00

I have got a method in my MVC 3 controller class, that accepts two

  • 0

I have got a method in my MVC 3 controller class, that accepts two parameters:

public ActionResult MyMethod(string providerName, IAuthProvider providerImpl)

I have got multiple implementations of IAuthProvider registered by its names in the Unity container as follows:

container.RegisterType<IAuthProvider, FacebookAuthProvider>("facebook");
container.RegisterType<IAuthProvider, GoogleAuthProvider>("google");

So, when the method is called I’d like the second argument to be resolved based on the first argument. For example, if the first argument was ‘facebook’ the second one must be resolved from the container to an IAuthProvider implementation registered by the name ‘facebook’.

I look forward to any ideas!

Remark: I use Unity.2.1.505.0

  • 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-03T17:21:35+00:00Added an answer on June 3, 2026 at 5:21 pm

    There’s so many things wrong with your example.

    1. Action Methods are not to be dependency injected with parameters, they are meant to be injected with values from the ModelBinder, that converts the name-value pairs that the browser is sending to objects that your action can accept.
    2. No DI framework can do the “bind the second parameter, based on first” out of the box because it is beyond their scope. If the DI can figure out what to inject for your IAuthProvider based on runtime values, it can only be because you have written some custom code for it.
    3. What you need is not in Unity, you need to write a custom ModelBinder for your requirements – Look here and here for examples. Extend the default ModelBinder, put a condition that if the action is MyMethod then look into the request values and self create the AuthProvider object and return the object.
    4. You can get the provider from the DI container, when you are writing your custom model binder. Also rethink the parameters, If your action is getting the correct provider, then why does it need the providerName? If it really needs it can it not get the name from the IAuthProvider itself? By checking the type or by using a .Name method? the providerName will only be used in the custom modelbinder
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I've got problem with foreach statement. I have my controller method: public ActionResult
inside my ASP.NET MVC controller, I've got a method that requires an HttpRequest object.
I have a controller in C# using the ASP.Net MVC framework public class HomeController:Controller{
I have got a JComponent. The paintComponent method is overridden. I mentioned that tooltips
I've got some 3rd party beans that have method signatures that fit quite well
The setup I have an MVC application that's making AJAX requests into my controller.
I got a plain spring3 web project set up and have a controller method
I have got method which is using Assembly.LoadFrom(...) statement and returns the supported cultures
I have got a textbox on a form with a method being called from
I have a main page which uses a ViewModel I have created: public class

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.