Does Ninject have and equivalent method for unity’s registerinstance.
I want to create a mock object and register it.
Thanks
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.
Here’s the simple answer
So here’s an example using Moq:
Bonus answer:
I find that some people are actually just looking to create a singleton instance of a particular class, rather than actually creating it themselves (this allows the object to be created when something requests it, rather than when you are building your container). This is done like this:
In your case, since you said the word “mock”, I’d assume you’d want the first rather than the second answer, but it’s a good thing to know.