我创建简单的WCF休息服务:Ninject在WCF休息服务托管在Windows服务
[ServiceContract]
public interface IReadData
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "GetHealthStatus")]
string GetHealthStatus();
}
和:
public class ReadData : IReadData
{
private IFacadeToRepo repository;
public ReadData(IFacadeToRepo connectorToRepo)
{
this.repository = connectorToRepo;
}
public string GetHealthStatus()
{
return "ok";
}
}
接下来,我创建了 “映射”:
class NinjectBindings: NinjectModule
{
public override void Load()
{
Bind<IReadData>().To<ReadData>();
Bind<IFacadeToRepo>().To<RepositoryApi>();
}
}
而且最后我创建了ServiceBase:
public partial class MyRestWCFRestWinSer : ServiceBase
{
ServiceHost readDataServiceHost = null;
private StandardKernel kernel;
public MyRestWCFRestWinSer()
{
kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
InitializeComponent();
}
public void OnDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
readDataServiceHost = new ServiceHost(kernel.Get<IReadData>());
readDataServiceHost.Open();
}
protected override void OnStop()
{
if (readDataServiceHost != null)
{
readDataServiceHost.Close();
readDataServiceHost = null;
}
}
}
所以我认为现在ninject应该解析IReadData并创建新的ReadData witch默认IFacadeToRepo。但它不起作用。通过installutil安装windows服务并运行processes - >我收到“服务正在启动,服务无法启动,服务没有报告错误。”
你能帮我将这些web服务与ninjects一起运行吗?
编辑。它看起来像它具有独特的有问题的:
kernel.Get<IReadData>()
后更换到:
的typeof(READDATA)
并添加默认情况下,空的构造函数READDATA - 它的工作原理
我做一些测试通过逐行添加行。
我一直在寻找一种解决方案,没有围绕托管在IIS中,我可以托管与TopShelf使用Windows服务,这解决了我的问题 - 希望我可以upvote不止一次 – JohnChris