views:

30

answers:

1

Hi all,

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!

A: 

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.

Joe R