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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:19:06+00:00 2026-06-05T23:19:06+00:00

I am very new to using dependency injection, and I am trying it out

  • 0

I am very new to using dependency injection, and I am trying it out with Ninject in my WPF application. I was wondering how should I be passing parameters across classes.

For e.g.

public class ViewPersonViewModel : ViewModelBase
{
    private IDataAccessService _dataService;
    private IPerson _person;
    private string _remarks;

    // binded to textbox
    public string Remarks
    {
        get { return _remarks; }
        set {
            if (_remarks != value) {
                remarks = value;
                OnPropertyChanged("Remarks");
            }
        }   
    }

    public ViewPersonViewModel(
        IDataAccessService dataService, IPerson person)
    {
        _dataService= dataService;
        _person = person;
    }

    // binded to Button
    public void RetrieveStatus()
    {
        Remarks = _dataService.RetrieveRemarks(_person);
    }
}

In here, dataService is a fixed class, where I presumably can do

class Module : Ninject.Modules.NinjectModule 
{
    public override void Load() 
    {
        Bind<IDataAccessService>().To<DefaultDataAccessService>();
    }
}

But I will like to know how should I handle the person parameter, where it is set by the calling class.

I saw from Creating an instance using Ninject with additional parameters in the constructor that it is possible to pass additional parameters in the constructor.

However, I have a few concerns:

  1. Is using kernel.Get<MyClass>( With.Parameters.ConstructorArgument( "parameterName", parameterValue) ); an ideal way? Wouldn’t it cause a lot of problems in debugging such as when you have typed your parameterName by mistake?

  2. Ruben also mentioned about using a more complicated way where Provider is involved. Is it applicable here? If it is, how can I use it?

  • 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-05T23:19:07+00:00Added an answer on June 5, 2026 at 11:19 pm

    Ninject 3 provided a convenient function that allows me to pass the parameters across classes. By creating an interface like

    public interface IViewPersonViewModelFactory()
    {
        IViewPersonViewModel CreateViewPersonViewModel([parameterType parameterName..]);
    }
    

    and adding the following to the Ninject module to be loaded:

    public override void Load()
    {
        Bind<IMainControllingViewModelFactory>().ToFactory();
        ... ... //other bindings
    }
    

    We can then obtain an instance of the ViewPersonViewModel class (for e.g. in the MainViewModel class)

     public class MainViewModel
     {
         private IViewPersonViewModel _viewModel;
    
         public MainViewModel(IViewPersonViewModelFactory viewModelFactory)
         {
             _viewModel = viewModelFactory.CreateViewPersonViewModel(parameters..);
         }
     }
    

    Note that no concrete factory has to be created.

    The wiki can be found at: https://github.com/ninject/ninject.extensions.factory/wiki/Factory-interface

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

Sidebar

Related Questions

I am very new to NTLM/LDAP and trying to authenticate using NTML running on
I am trying to figure out how to create multiple objects when using Dependency
During the design of a new application I was wondering if using a module
Very new to using Raphael.js I'm looking at the tutorials and I am able
I am very new to using SQL and I haven't been able to find
I'm very new to Ruby and using Sinatra, mainly so that I can do
I am very new to nservicebus. I am using version 3.0.1, the last one
I am very new to dictionaries. Very new meaning that I started using them
So I'm very new to JSF, I just started using it a few days
I'm very new to trigger function. Actually this is the first time I'm using

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.