This is my project diagram (in shortcut). I'm using Ninject to resolve DI in my solution.
I have a problem with my WCF Service in Friends.Implementation
library.
When I have Friends.svc and Friends.svc.cs file in MyWCFService
, everything is OK (DI and Ninject works).
But when I move Friends service into separate library, I get this error:
The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.
Why I get that error? How to resolve it?
This is my service code:
<%@ ServiceHost Language="C#" Debug="true" Service="XYZ.Services.Friends" CodeBehind="Friends.svc.cs" Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory" %>
.CS file
public IAccountService accountService { get; set; }
public IFriendsService friendsService { get; set; }
public Friends(IAccountService _acc, IFriendsService _friends)
{
this.accountService = _acc;
this.friendsService = _friends;
}
Regards.
对于单独库中的服务,应从ServiceHost
删除CodeBehind="Friends.svc.cs"
属性,并且Service
属性应与服务实现的标准程序集名称匹配
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.