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!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…