I want to provide some context for people, since I was confused at first by your answer JC.
public Program {
//
// Static constructor
//
static Program() {
// Set up Ninject
var kernel = new StandardKernel();
// Register bindings
RegisterServices(kernel);
// Set up Ninject logging config
NLog.Config.ConfigurationItemFactory.Default.CreateInstance =
(type) => kernel.TryGet(type);
// Continue on!
}
private static void RegisterServices(IKernel kernel) {
// bind services!
kernel.Bind<IMyClass>().To<MyClass>();
}
}
[Target("Custom")]
public class CustomTarget : TargetWithLayout {
private IMyClass _myClass;
public CustomTarget(IMyClass myClass) {
// This will be injected!
_myClass = myClass;
}
}
This shows how you set up the instance creation and how it all fits together with NLog. Hope that helps other people!
ConfigurationItemFactory.Default.CreateInstance
. For Ninject, this would simply be:ConfigurationItemFactory.Default.CreateInstance = (type) => Kernel.TryGet(type)
, but JC provides a better modular pattern. – Smite