WCF integration

43 views
Skip to first unread message

pan

unread,
Jan 11, 2008, 8:22:26 AM1/11/08
to Autofac
Hi Nicholas,

I was recently evaluating the available .NET Dependency Injection
containers, and (I must say) Autofac seemed the best choice for me
(lightweight, elegant, active developer base :-)
One of the technologies I'm bound to use on my next project is also
WCF, so I tried to use Autofac with it. Using
http://orand.blogspot.com/2006/10/wcf-service-dependency-injection.html
and http://www.castleproject.org/container/facilities/trunk/wcf/index.html
I wrote the several classes needed to integrate WCF & Autofac and it
seems to work fine - if you wish, I can send you the files.
One thing though - I wanted to support injection of additional WCF
service and endpoint behaviours via Autofac, but to accomplish that
one needs to be able to obtain (from the container) all the components
(there can be more than one) that implement certain service (in this
case IServiceBehavior & IEndpointBehavior). I could not find a way to
do this - is it even possible to register multiple components for the
same service type?
Txs!

regards,
Peter

Nicholas Blumhardt

unread,
Jan 12, 2008, 2:44:35 AM1/12/08
to Autofac
Hi Peter,

That's excellent to hear! Please do send your integration - I think
you can upload files to this group, if not then please email me.

Autofac does support multiple registrations for the same service,
though there is no efficient way to expose that information right now
so it isn't part of the container's interface. Each
IComponentRegistration associated with the container has a Services
member - so by iterating over all of the registrations and the
services that they expose, it is possible... There are a couple of
caveats but It wouldn't be hard to add something like:

IEnumerable<IComponentRegistration> Container.GetComponents(Service
service);

An approach you might consider however is to add the handler when the
component is registered:

component.Activating += (sender, e) => {
var sb = (IServiceBehaviour)e.Instance;
// ...
};

Does this make sense in this case? If you're registering WCF services
using an extension to ContainerBuilder then it should be
straightforward to do this way (the IRegistrar interface returned from
most of the Register methods exposes OnRegistered for this purpose.)

I'm looking forward to experimenting with your WCF code, I should be
able to offer a more concrete suggestion for your requirements then.

Thanks again for posting.

Nick

On Jan 11, 11:22 pm, pan <Petar.Andrijase...@gmail.com> wrote:
> Hi Nicholas,
>
> I was recently evaluating the available .NET Dependency Injection
> containers, and (I must say) Autofac seemed the best choice for me
> (lightweight, elegant, active developer base :-)
> One of the technologies I'm bound to use on my next project is also
> WCF, so I tried to use Autofac with it. Usinghttp://orand.blogspot.com/2006/10/wcf-service-dependency-injection.html
> andhttp://www.castleproject.org/container/facilities/trunk/wcf/index.html

pan

unread,
Jan 12, 2008, 9:21:59 AM1/12/08
to Autofac
Hi Nicholas,

I uploaded the zipped solution...
Concerning the injection of additional behaviors - this not an issue
for me, I just wanted to do it for completeness sake.
Another point is the method
AutofacInstanceProvider.ReleaseInstance(...). This method (obviously)
could be used to make disposal, maybe using inner containers...

regards,
Peter

On Jan 12, 8:44 am, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:

Nicholas Blumhardt

unread,
Jan 13, 2008, 5:18:28 AM1/13/08
to Autofac
Looks good, Peter. I understand what you mean about implementing
ReleaseInstance() using an inner container, I'll have a look at how it
might be done....
Nick

Nicholas Blumhardt

unread,
Jan 17, 2008, 11:21:40 PM1/17/08
to Autofac
The code is now in the repository and is part of the main solution.

Thanks Peter for your fantastic work!

I'll endeavour to make some documentation available on the Wiki soon.
The simple example Peter created is checked in under the trunk/
examples folder.

On Jan 13, 8:18 pm, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages