我需要自动解决我的 Windows 窗体的依赖关系。唯一的问题是我的表单构造函数也需要一个整数值。请查看代码部分中的实现。
//Ninject bindings
public class Bindings : NinjectModule
{
public override void Load()
{
Bind<ILogger>().To<LogToDB>();
Bind<ICopy>().To<CopyToFolder>();
}
}
//WinForm - Form1
public partial class Form1 : Form
{
public readonly ILogger _processRepository;
public readonly Icopy _copy;
public readonly int ValueToEdit;
public Form1(int valueToEdit, ILogger logger, ICopy copy)
{
this._processRepository = logger;
this._copy = copy;
this.ValueToEdit = valueToEdit;
InitializeComponent();
}
}
//main
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
IKernel kernel = new StandardKernel(new Bindings());
Application.Run(kernel.Get<Form1>());
}
我得到一个错误:Ninject.ActivationException: 'Error activating int No matching bindings are available, and the type is not self-bindable.
如何自动解析表单依赖关系并传递整数值?实际上,我使用了相同的表格来进行添加和编辑,所以在编辑时,应该设置这个编辑值。
慕容708150
牧羊人nacy
相关分类