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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:43:57+00:00 2026-06-08T23:43:57+00:00

I have constructor Foo(IColor c , int someNumber) and I know the some number

  • 0

I have constructor

Foo(IColor c , int someNumber)

and I know the some number only during the run time, and I want to call this constructor during the resolving and to pass someNumber value and the IColor to be resolved autocratically.

Something like this:

container.Resolve<IFoo>(someNumber);

Is it possible to be done ?

  • 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-08T23:43:58+00:00Added an answer on June 8, 2026 at 11:43 pm

    Yes, pass the constructor arguments in an instance of an anonymous type; the property names must match the constructor parameter names:

    IColor desiredColor = //whatever
    int desiredNumber = //whatever else
    IFoo foo = container.Resolve<IFoo>(new { c = desiredColor, somenumber = desiredArgumentValue });
    

    If you are using an older version of C# that does not support anonymous types (or even if you’re not), you can do the same with a dictionary:

    IColor desiredColor = //whatever
    int desiredNumber = //whatever
    Dictionary<string, object> arguments = new Dictionary<string, object>();
    arguments.Add("c", desiredColor);
    arguments.Add("somenumber", desiredNumber);
    IFoo foo = container.Resolve<IFoo>(arguments);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function-constructor. I want to control what function (object) can call it. Here'e
I want to know that if I have this in my constructor: public class
I have a constructor method similar to this: public class Foo { public Foo
I have a final member data: public final Foo foo; in the constructor, foo
I have Constructor Tree(int a, int b, int c) and second Constructor Tree(int a,
I have a constructor for my class: class(ofstream & o) . I want to
In a class, I have: private Foo bar; public Constructor(Foo bar) { this.bar =
I have a class called Foo with a constructor that needs arguments, and a
I have a class Foo that uses another class Bar to do some stuff.
I have tried to use C++0x initializer list as argument to a constructor call

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.