Autofac WcfIntegration – Service not registered with the Autofac container

Today was my first time trying to setup Autofac with WcfIntegration.

Following the instructions to the letter (almost!) I couldn’t get it to work.

I was getting the error:

The service ‘MyService’ configured for WCF is not registered with the Autofac contain

My config was fairly simple, but I still tried changing this for a good hour!

var builder = new ContainerBuilder();
builder.Register(c => new PNRResolverService(c.Resolve()));
builder.RegisterType();
AutofacHostFactory.Container = builder.Build();

After much googling and turning up no results I went back to the wiki and checked the comments (Yes, I probably should have done this first).

I found my answer six comments down!

it looks like you need to use the fully-qualified name of your service in the .SVC file

Looks like I missed a small but very important part of the example in the wiki

And your .svc file would specify the appropriate service implementation type and host factory, like this:

<%@ ServiceHost Service="TestService.Service1, TestService" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>

Note the Service="TestService.Service1, TestService"

I changed that one tiny bit of my .svc file from `MyProject.MyService` to MyProject.MyService, MyProject and it worked perfectly!

This entry was posted in .NET Development and tagged , . Bookmark the permalink.

5 Responses to Autofac WcfIntegration – Service not registered with the Autofac container

  1. Joe Collins says:

    Thanks for the post – it helped me figure this out in 5 minutes; otherwise I’m sure I’d have spent at least an hour on it also.

  2. Vincent says:

    Wow, after several hours….how simple can it be ! Thanks !

  3. Sebastian says:

    I thank you sooooo much.
    Took me hours to investigate and being the problem so close I can’t even see it without your help.

  4. Bryant Sharp says:

    I spent most the day on this…MyProject.MyService, MyProject …..thank very much!!!

  5. santosha_wine says:

    Thank you so much! I wish I could gift you reddit gold.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>