How do I pass an object to a constructor argument with Ninject? Assuming the object is register in the container.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Apparently you do not need to explicitly provide Ninject with constructor arguments if the dependent objects are defined in the container. This is unlike Castle.
Here’s an example. IGitRepository depends on IGitAuthor and IGitRepositoryPath. Since the two dependents are bond in my container they are injected ‘magically’. Ninject is smart enough to see that IGitRepository’s constructor takes them. So I just bind IGitRepository and leave off the .withConstructorArgument(s).