Ninject 与 ria 域服务标准 asp.net web 应用程序
我想将 DI (Ninject) 与位于标准 asp.net Web 服务器上的 RIA Web 服务一起使用。
我应该如何连接包含数据存储的存储库?
我添加了一个 Global.asax 文件:
public class Global : NinjectHttpApplication
{
protected override Ninject.IKernel CreateKernel()
{
IKernel kernel = new StandardKernel();
kernel.Bind<IPersonRepository>().To<PersonRepository>();
Application.Add("Kernel", kernel);
return kernel;
}
这是我想连接它的地方,...但我被卡住了
[EnableClientAccess]
public class PersonService : DomainService
{
IPersonRepository _personRepository;
public PersonService()
{
_personRepository = ????....kernel.Get<IPersonRepository>();
}
}
似乎我只是缺少一种获取应用程序对象的方法,然后它就可以工作了,或者?
I would like to use DI (Ninject) with my RIA webservices which is located on a standard asp.net webserver.
How should I hook up my repositories containing the datastore?
I've added a Global.asax file :
public class Global : NinjectHttpApplication
{
protected override Ninject.IKernel CreateKernel()
{
IKernel kernel = new StandardKernel();
kernel.Bind<IPersonRepository>().To<PersonRepository>();
Application.Add("Kernel", kernel);
return kernel;
}
And here's where I would like to hook it up,...but I'm stuck
[EnableClientAccess]
public class PersonService : DomainService
{
IPersonRepository _personRepository;
public PersonService()
{
_personRepository = ????....kernel.Get<IPersonRepository>();
}
}
It seems that I'm only missing a way to get the application object and then it would work, or?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我本身没有 RIA Web 服务的经验,但在快速浏览文档后,我建议执行以下操作。创建 IDomainServiceFactory 用于 Ninject。
使用 DomainService 类。
确保您向内核注册了域服务和任何依赖项。 IPersonRepository 应该被注入到 PersonService 的构造函数中。
希望这会有所帮助,因为我自己还没有尝试过该解决方案。
I have no experience of RIA Web Services per se, but after a quick scan of the documentation I would suggest doing the following. Create an implementation of IDomainServiceFactory for Ninject.
Register the custom domain service factory with the DomainService class in Application_Start.
Make sure you register your domain services and any dependencies with the kernel. The IPersonRepository should be injected in the constructor of the PersonService.
Hopefully this will be helpful as I haven't tried the solution myself.