WCF in a windows service

163 views
Skip to first unread message

Martin Fabik

unread,
May 2, 2010, 8:35:32 AM5/2/10
to Autofac
I'd like to inject my WCF services using Autofac on server side. In
the wiki there is just an example with a service hosted in IIS, but my
services are hosted in a windows service. In the IIS example there is
a factory attribute, but there is no factory attribute on the service
element in the app.config. So I'm just curious where should I define
the factory attribute ?

--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To post to this group, send email to aut...@googlegroups.com.
To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/autofac?hl=en.

Nicholas Blumhardt

unread,
May 2, 2010, 4:41:00 PM5/2/10
to aut...@googlegroups.com
Hi Martin,

You need to add an AutofacDependencyInjectionServiceBehaviour to the service when you create it. This can be done by hooking the Opening event as in: http://code.google.com/p/autofac/source/browse/trunk/src/Source/Autofac.Integration.Wcf/AutofacHostFactory.cs

I haven't used Autofac in this scenario myself, there may be some rough edges here so please follow up if you encounter any trouble.

Cheers,
Nick
Message has been deleted

Martin Fabik

unread,
May 6, 2010, 10:18:55 AM5/6/10
to Autofac
What should I insert as the IComponentRegistration registration
parameter in the AutofacDependencyInjectionServiceBehavior ctor ?

On 2 kvě, 22:41, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:
> Hi Martin,
>
> You need to add an AutofacDependencyInjectionServiceBehaviour to the service
> when you create it. This can be done by hooking the Opening event as in:http://code.google.com/p/autofac/source/browse/trunk/src/Source/Autof...
>
> <http://code.google.com/p/autofac/source/browse/trunk/src/Source/Autof...>I
> haven't used Autofac in this scenario myself, there may be some rough edges
> here so please follow up if you encounter any trouble.
>
> Cheers,
> Nick
>
> On 2 May 2010 22:35, Martin Fabik <fabik.mar...@gmail.com> wrote:
>
>
>
>
>
> > I'd like to inject my WCF services using Autofac on server side. In
> > the wiki there is just an example with a service hosted in IIS, but my
> > services are hosted in a windows service. In the IIS example there is
> > a factory attribute, but there is no factory attribute on the service
> > element in the app.config. So I'm just curious where should I define
> > the factory attribute ?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Autofac" group.
> > To post to this group, send email to aut...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > autofac+u...@googlegroups.com<autofac%2Bunsu...@googlegroups.com >
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/autofac?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Autofac" group.
> To post to this group, send email to aut...@googlegroups.com.
> To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/autofac?hl=en.

Alex Meyer-Gleaves

unread,
May 7, 2010, 9:16:31 AM5/7/10
to aut...@googlegroups.com
Hi Martin,

I have written a blog post that describes how to use the Autofac WCF Integration when Self-Hosting WCF Services.

http://alexmg.com/post/2010/05/07/Self-Hosting-WCF-Services-with-the-Autofac-WCF-Integration.aspx

That should be enough to point you in the right direction.

Cheers,

Alex.

On 5 May 2010 05:07, Martin Fabik <fabik....@gmail.com> wrote:
I've looked at the link you posted but I don't get it :-) Should I
create the ServiceHost using the CreateService method ? If yes what
should be passed as the constructorStrin ??

If you could give me a small example, that would be very nice.

This is my class for setting up the services.

   internal class ServiceManager
   {
       readonly List<ServiceHost> services = new List<ServiceHost>();

       public void RunServices()
       {
           this.SpustSluzbu<Service1>();
           this.SpustSluzbu<Service2>();
           this.SpustSluzbu<Service3>();
       }


       public void CloseAllServices()
       {
           this.services.ForEach(host => host.Close());
       }

       private void RunService<T>()
       {


           ServiceHost service= new ServiceHost(typeof(T));
           service.Open();

           services.Add(sluzba);
       }
   }

Thank you in advance!!



On 2 kvě, 22:41, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:
> Hi Martin,
>
> You need to add an AutofacDependencyInjectionServiceBehaviour to the service

> haven't used Autofac in this scenario myself, there may be some rough edges
> here so please follow up if you encounter any trouble.
>
> Cheers,
> Nick
>
> On 2 May 2010 22:35, Martin Fabik <fabik.mar...@gmail.com> wrote:
>
>
>
>
>
> > I'd like to inject my WCF services using Autofac on server side. In
> > the wiki there is just an example with a service hosted in IIS, but my
> > services are hosted in a windows service. In the IIS example there is
> > a factory attribute, but there is no factory attribute on the service
> > element in the app.config. So I'm just curious where should I define
> > the factory attribute ?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Autofac" group.
> > To post to this group, send email to aut...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > .
> > For more options, visit this group at
> >http://groups.google.com/group/autofac?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Autofac" group.
> To post to this group, send email to aut...@googlegroups.com.
> To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/autofac?hl=en.


--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To post to this group, send email to aut...@googlegroups.com.
To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/autofac?hl=en.

Alex Meyer-Gleaves

unread,
May 7, 2010, 9:52:26 AM5/7/10
to aut...@googlegroups.com
Hi Martin,

I have also updated the documentation on the Wiki.

http://code.google.com/p/autofac/wiki/WcfIntegration

Cheers,

Alex.

On 5 May 2010 05:07, Martin Fabik <fabik....@gmail.com> wrote:
I've looked at the link you posted but I don't get it :-) Should I
create the ServiceHost using the CreateService method ? If yes what
should be passed as the constructorStrin ??

If you could give me a small example, that would be very nice.

This is my class for setting up the services.

   internal class ServiceManager
   {
       readonly List<ServiceHost> services = new List<ServiceHost>();

       public void RunServices()
       {
           this.SpustSluzbu<Service1>();
           this.SpustSluzbu<Service2>();
           this.SpustSluzbu<Service3>();
       }


       public void CloseAllServices()
       {
           this.services.ForEach(host => host.Close());
       }

       private void RunService<T>()
       {


           ServiceHost service= new ServiceHost(typeof(T));
           service.Open();

           services.Add(sluzba);
       }
   }

Thank you in advance!!


On 2 kvě, 22:41, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:
> Hi Martin,
>
> You need to add an AutofacDependencyInjectionServiceBehaviour to the service

> haven't used Autofac in this scenario myself, there may be some rough edges
> here so please follow up if you encounter any trouble.
>
> Cheers,
> Nick
>
> On 2 May 2010 22:35, Martin Fabik <fabik.mar...@gmail.com> wrote:
>
>
>
>
>
> > I'd like to inject my WCF services using Autofac on server side. In
> > the wiki there is just an example with a service hosted in IIS, but my
> > services are hosted in a windows service. In the IIS example there is
> > a factory attribute, but there is no factory attribute on the service
> > element in the app.config. So I'm just curious where should I define
> > the factory attribute ?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Autofac" group.
> > To post to this group, send email to aut...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > .
> > For more options, visit this group at
> >http://groups.google.com/group/autofac?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Autofac" group.
> To post to this group, send email to aut...@googlegroups.com.
> To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/autofac?hl=en.


--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To post to this group, send email to aut...@googlegroups.com.
To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/autofac?hl=en.

Martin Fabik

unread,
May 8, 2010, 4:53:29 PM5/8/10
to Autofac
Hi Alex.

Thanks to your article, I got it finally working !! Works like a
charm :-)
Reply all
Reply to author
Forward
0 new messages