Wcf有很多依賴注入的例子,但其中很多都處理4.0之前的Wcf版本。我有一個用Wcf 4 Rest構建的應用程序,沒有.svc文件,基本上看起來像這樣。WCF Rest 4依賴注入
public class RestService : IRestService
{
IUserRepository _userRepo;
public RestService(IUserRepository repo)
{
_repo = repo;
}
public UserModel GetUser(int id)
{
return _repo.GetUserById(id);
}
}
public interface IRestService
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/User/{id}",
BodyStyle = WebMessageBodyStyle.Bare)]
UserModel GetUserById(int id);
}
就像我說的,沒有svc文件,整個九碼。只是這在global.asax文件
RouteTable.Routes.Add(new ServiceRoute("RestService", new WebServiceHostFactory(), typeof(RestService)));
所以,我想要使用Castle Windsor注入UserRepository。
使用Castle Windsor 4.0設置服務的最佳方式是什麼?
我認爲WCF Facility支持那不是嗎? –
它確實如此,我已經在許多應用程序中使用過WCF工具,它相當方便地完成了這一工作。 –