我的 ninject 扩展名的 wcf 服务有问题。当我的服务在我试图调用它时没有无参数构造函数时,当我得到无参数构造函数时,我得到了错误,我错过了它:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class ContractService: IContractService
{
public ContractService()
: this(new AddressService(), new TelephoneService())
{
}
[Inject]
public ContractWCFService(IAddressService addressService, ITelephoneService telephoneService)
{
_addressService = addressService;
_telephoneService = telephoneService;
}...
}
然后,调用无参数的一个,我认为应该调用具有属性 [Inject] 的第二个。
编辑:NinjectWebCommon:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<ServiceHost>().To<NinjectServiceHost>();
kernel.Bind<IAddressService>().To<AddressService>().InHttpRequestScope();
kernel.Bind<TelephoneService>().To<TelephoneService>().InHttpRequestScope();
kernel.Bind(typeof(IRepository<>)).To(typeof(Repository<>)).InHttpRequestScope();
kernel.Bind(typeof(EFModel)).ToSelf().InHttpRequestScope();
IoC.Initialize((StandardKernel)kernel);
}
有任何想法吗?