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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:11:50+00:00 2026-06-05T00:11:50+00:00

I’m developing an ASP.NET MVC 3 project using NInject to create object instances. It

  • 0

I’m developing an ASP.NET MVC 3 project using NInject to create object instances. It builds an object graph for each Action. It works well in most cases. However, I have a new requirement that I must pass some parameters (from request) to a few objects (which are transient) in the object graph.
How can I do that? Here is an example:

class MyController : Controller
{
    [Inject]
    public IProcess Process {get;set;}

    public ActionResult MyAction(int value)
    {
         // how to pass the 'value' to an object (IOptions) created by NInject
         this.Process.Run();
    }
}

As shown in the code above, the Process property is injected with an instance of IProcess created by NInject. There is a complex object graph behind the scene. And I want to pass the ‘value’ to one of the objects in the object graph which is an transient instance of IOptions used by the IProcess instance. The IOptions interface has a method named SetValue(int).

The thing I want to do is, when the IOptions object is created, it’s SetValue(int) will be called. Of course, it should be thread-safe.

Any idea?

  • 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-05T00:11:50+00:00Added an answer on June 5, 2026 at 12:11 am

    Hy
    This can be achieved with either a custom factory or the Ninject.Factory.Extension which does all the magic behind the scenes. I’ll show here the manual approach:

    public interface IProcessFactory {
       IProcess Create(int value);
    }
    
    public class ProcessFactory : IProcessFactory {
        public IProcess Create(int value)
        {
            return this.kernel.Get<IProcess>(new Parameter("value", value, true));
        }
    }
    

    somewhere in a module:

            this.Bind<IProcess>().To<Process>();
            this.Bind<IOption>().To<Option>()
                .OnActivation((ctx, o) => o.SetValue((int)ctx.Parameters.Single(p => p.Name == "value").GetValue(ctx, ctx.Request.Target)));
    

    I think there should be also an extension method somewhere in a ninject extension which allows to simplify the OnActivation call.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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
i got an object with contents of html markup in it, for example: string

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.