在我的 Ninject 绑定模块中,
public class CarModule : NinjectModule
{
public override void Load()
{
Kernel.Bind(scanner => scanner.FromThisAssembly().SelectAllClasses()
.InheritedFrom<ICar>().BindAllInterfaces());
foreach (var binding in kernel.GetBindings(typeof(ICar)))
{
Trace.WriteLine(string.Format("[{0}] Service bound to [{1}]",
binding.Service.Name,
binding.Target.GetType().Name));
}
// Output looks like:
//[ICar] Service bound to [BindingTarget]
//[ICar] Service bound to [BindingTarget]
//[ICar] Service bound to [BindingTarget]
}
}
我需要进行健全性检查以查看已成功绑定到我的服务的类型。我无法访问绑定类型的类型名称。而不是[BindingTarget]
, 我想看到[Mercedes]
, [Ferrari]
, 等等...
有没有好的和/或常见的方法来做到这一点?