Note that there are some explanatory texts on larger screens.

plurals
  1. PODependency Injection fix using Ninject?
    text
    copied!<h2><strong>Question</strong></h2> <p>Do you have any other point that supports Ninject other then below mentioned two points?</p> <p>============</p> <h2><strong>Details</strong></h2> <ol> <li><p>We don't need to pass the instance to any constructor wherever we need Employee instance.</p></li> <li><p>We may have a situation when two classes have same functions so using the common Interface for these classes.</p></li> </ol> <h2><strong>Example Code</strong></h2> <pre><code>class Sword : IWeapon { public void Hit(string target) { Console.WriteLine("Chopped {0} clean in half", target); } } class Shuriken : IWeapon { public void Hit(string target) { Console.WriteLine("Pierced {0}'s armor", target); } } </code></pre> <p>Both are using same Interface. This link says that we may have different classes, which have common Interface.</p> <h2><strong><a href="https://github.com/ninject/ninject/wiki/Dependency-Injection-By-Hand" rel="nofollow">Click here to check the link</a></strong></h2> <p>But, in my case there in no such situation, where I have two classes using the common Interface</p> <p>Using the <strong>Ninject Dependency Resolver</strong>, and using the below code, we can fix this issue</p> <pre><code>var kernel = new StandardKernel(); kernel.Bind&lt;Practise.Models.IEmployee&gt;().To&lt;Practise.Models.Employee&gt;(); DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); </code></pre> <p>Using this code, I don't need to pass the Employee instance to any constructor.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload