2

In a short view of the IoC and DI .NET libraries I chose to use Ninject2. According to DDD style in:

  • Infrastructure: I have Entity Framework 4.0 .edmx model and the Repository implementation
  • Domain Layer: I have POCO objects and Repository Interfaces (implemented in Infrastructure)
  • Application Services: I have WCF services that call methods defined in repository interfaces from Domain Layer.

My question is how to inject a Repository in WCF with Ninject2. I have read some articles with Ninject2 but are presented very simple example ( ex.: dependency injection in the same class library). Any indication would be useful:).

Many many thanks!

4

1 回答 1

6

如果您下载 Ninject 2 WCF 扩展,您应该能够很好地完成此操作。

主要区别在于您的 svc 文件有一个 Factory 条目:

<%@ ServiceHost Language="C#" Debug="true" Service="WcfService.YourService" CodeBehind="YourService.svc.cs" Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory" %>

并且您的 global.asax.cs 文件继承自 NinjectWcfApplication:

namespace WcfService
{
    public class Global : NinjectWcfApplication

可以在此处找到其余代码和服务示例。

于 2010-09-30T15:50:42.813 回答