我对Ninject很新,我的情况是这样的: 我有两个ClassA和ClassB类,分别有iClassA和iClassB接口。课程如下:
public ClassA()
{
private ClassB _clsb;
private String _trustKey;
public class ClassA(ClassB clsB)
{
_clsb = clsB;
}
public string getTrustKey()
{
this._trustKey = _clsb.trustKey
return this._trustKey;
}
}
public class ClassB()
{
private string _trustKey;
public ClassB(string trustkey)
{
_trustKey = trustKey;
}
public string trustKey()
{
get { return _trustKey; }
set { _trustKey = value; }
}
}
我有一个控制器类及其构造函数
public class controller : ApiController
{
private iClassA _iclsA;
public mycontroller(iClassA clsA)
{
_iclassA = clsA;
}
public string getTrustKey()
{
clsA.getTrustKey();
}
}
如何在运行时初始化ClassB的trustkey值,以便在控制器构造函数中调用classA时,classB将使用运行时值初始化其trustkey。当我使用像kernel.bind<iclassA>.To<ClassA>()
和kernel.bind<iClassB>.To<ClassB>()
这样的内核绑定时
let numberFromAddressBook = "+1 818 323 323 323"
let cleanNumber = numberFromAddressBook.stringByReplacingOccurrencesOfString("[^0-9+]", withString: "", options: NSStringCompareOptions.RegularExpressionSearch, range:nil)
"+1818323323323"
,我无法为classB的trustkey分配值。
先谢谢!