Is the example below dependency injection with regard to the Worker class? From my reading about the topic over the last few hours becaue the Worker class isn't obtaining the ITool instance from a property setter or constructor it isn't an example of DI?
public MainClass {
static void Main(string[] args) {
ITool someTool = new Tool();
MyContainer.Register<ITool>(someTool);
}
}
public class MyContainer {
private WindsorContainer container;
public MyContainer() {
container = new WindsorContainer();
}
public static T Resolve<T>() {
return container.Resolve<T>();
}
public static void Register<T>(object instance) {
container.Kernel.AddComponentInstance(typeof(T).ToString(), typeof(T), instance);
}
}
public class Worker {
public DoSomeWork() {
ITool tool = MyContainer.Resolve<ITool>();
tool.DoTheWork();
}
}