Adding IoC Support to my WCF service hosted in a windows service (Autofac)

Posted by user137348 on Stack Overflow See other posts from Stack Overflow or by user137348
Published on 2010-05-07T08:06:04Z Indexed on 2010/05/07 8:08 UTC
Read the original article Hit count: 331

Filed under:
|
|
|

I'd like to setup my WCF services to use an IoC Container. There's an article in the Autofac wiki about WCF integration, but it's showing just an integration with a service hosted in IIS.

But my services are hosted in a windows service.

Here I got an advice to hook up the opening event http://groups.google.com/group/autofac/browse_thread/thread/23eb7ff07d8bfa03

I've followed the advice and this is what I got so far:

    private void RunService<T>()
    {
        var builder = new ContainerBuilder();

        builder.Register(c => new DataAccessAdapter("1")).As<IDataAccessAdapter>();

        ServiceHost serviceHost = new ServiceHost(typeof(T));

        serviceHost.Opening += (sender, args) => serviceHost.Description.Behaviors.Add(
            new AutofacDependencyInjectionServiceBehavior(builder.Build(), typeof(T), ??? ));                      


        serviceHost.Open();
     }

The AutofacDependencyInjectionServiceBehavior has a ctor which takes 3 parameters. The third one is of type IComponentRegistration and I have no idea where can I get it from. Any ideas ?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ioc

Related posts about autofac