我对Ninject很新,但我已成功使用自定义提供程序将其用于DI.
绑定初始化如下
kernel = new StandardKernel();
kernel.Bind<IPatientRecordLocator>().ToProvider<PatientRecordLocatorProvider>();
Run Code Online (Sandbox Code Playgroud)
在自定义提供程序中,我像这样调用Activator.CreateInstance
protected override IPatientRecordLocator CreateInstance(IContext context)
{
var name = ConfigurationManager.AppSettings["PatientRecordLocator"];
var typeName = name.Split(',')[0];
var assemblyName = name.Split(',')[1];
return Activator.CreateInstance(assemblyName, typeName).Unwrap() as IPatientRecordLocator;
}
Run Code Online (Sandbox Code Playgroud)
(是的,我知道上面的代码中没有错误处理等:))
而这一切都像一个魅力.
现在,我面临的问题是当我引入一个我希望注入IPatientRecordLocator实例的新类时.当我向其中一个类添加如下构造函数时,会出现问题
[Inject]
public MockPatientRecordLocator (IContactAdapter contactAdapter)
{
...
}
Run Code Online (Sandbox Code Playgroud)
然后,为了使Activator.CreateInstance工作,我还必须向类MockPatientRecordLocator添加一个无参数构造函数,即
public MockPatientRecordLocator()
{
}
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:如何让Ninject注入一个实现IContactAdapter的类的实例到例如MockPatientRecordLocator?我尝试过注射方法,但无济于事.
我忘了解释我正在尝试实现的是一种链式注入,其中一个类PatientRecordSummary的实例被注入一个MockPatientRecordLocator实例(使用构造函数注入),并且所述MockPatientRecordLocator实例应该注入一个IContactAdapter实例(再次使用构造函数注入(如果可能)).链的第一部分工作,第二部分没有.
希望有人可以帮助我.我有以下观点:
<label repeat.for="option of options">
<input type="radio" name="periodOptions" model.bind="option" checked.bind="$parent.selectedOption" click.delegate="clicked()"/>
${option.text}
</label>
Run Code Online (Sandbox Code Playgroud)
和以下viewmodel:
export class PeriodPanel {
heading = 'Tidsperiode';
options = [];
selectedOption = {};
constructor() {
this.options = [
{id:1, text:'Vis med dagoppløsning'},
{id:2, text:'Vis med timeoppløsning'},
{id:3, text:'Vis periode'}
];
this.selectedOption = this.options[0];
}
clicked() {
console.log(this.selectedOption.id);
}
}
Run Code Online (Sandbox Code Playgroud)
分配的原因this.selectedOption = this.options[0];是确保最初设置了一个单选按钮.这很好看,但是当我依次点击每个单选按钮时,selectedOption变量的值不会改变,click-handler clicked()将每次打印值1.我究竟做错了什么?
TIA
Caliburn.Micro 3.0(和Caliburn.Micro.Xamarin.Forms)是否实现了模拟/支持Navigation.PushModalAsyncXamarin.Forms的功能?