IOC with WCF…

So if you have used a repository pattern with WCF and tried to run the built-in WCF Client app you most likely have seen this error:

The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.

You get this when your Servce class looks something like this:

public class SiteService : Service, ISiteService
{
private readonly IRepositoryAsync _asynRepository;

public SiteService(IRepositoryAsync repository)
: base(repository)
{
_asynRepository = repository;
}

That is expected because the IInstanceProvider only works with empty default constructors (with a few exceptions) and as you can see we are expecting a dependency.  In this case a repository, but it could be any dependency such as another service.

Anyway, I know Ninject provides a solution you can get from the Nuget library via the Ninject.Extensions.Wcf, but…. I want to try out using Unity and from what I understand there are community supported solutions too.

…. More to come…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s