开发者

How to use Ninject2 with WCF?

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 interfac开发者_C百科es 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!


If you download the Ninject 2 WCF extensions you should be able to do this quite nicely.

The main differences are that your svc file has a Factory entry:

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

and your global.asax.cs file inherits from NinjectWcfApplication:

namespace WcfService
{
    public class Global : NinjectWcfApplication

The rest of the code and service examples can be found here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜