Public interface IWeapon { void Strike(); } public class Sword : IWeapon { public void Strike() { Console. WriteLine("black ninja strike"); } } public class Ninja { private readonly IWeapon _weapon; public Ninja(IWeapon weapon) { _weapon = weapon; } public void Strike() { _weapon.Strike(); } } public class WarriorModule : NinjectModule { public override void Load() { Bind().To(); } } class Program { static void Main() { var kernel = new StandardKernel(new WarriorModule()); var ninja = kernel.Get(); ninja.Strike(); } }.
Wouldn't it just be: var ninja = Kernel.Get(); You obviously have to resolve the dependency though Ninject.
– Adam Tegen May 2 at 22:24 @Adam Tegen: thankfully no. Have a search for Service Locator antipattern and go read @Mark Seemann's top-votes answers for the why.(Some Ninject extensions do have a KernelContainer object, but that's only on an as-needed-basis and definitely not a core feature) – Ruben Bartelink May 3 at 23:58 For ASP.NET you might be right. For MVVM, I think I need to a talk with Mark about it.
Also, performance can also sometimes justify the use of antipatterns. – Claus Jørgensen May 4 at 2:12 Also, I think you meant this article: blog.ploeh. Dk/2010/02/03/ServiceLocatorIsAnAntiPattern.
Aspx – Claus Jørgensen May 4 at 2:19.
You need to have an instance of StandardKernel let's call it kernel and then use kernel.Get(). This works since Ninja is non abstract, so it is considered bound to itself. Obviously some concrete types needs to be bound to IWeapon to allow NInject to create Ninja.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.