Cargo
Cargo

Reputation: 185

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:

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!

Upvotes: 2

Views: 1125

Answers (1)

Joe Ratzer
Joe Ratzer

Reputation: 18549

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.

Upvotes: 6

Related Questions