A few weeks ago I wrote an article about using IoC with BizTalk and Castle Windsor. A few of the guys who I trust know their stuff really well told me that they were using Autofac which is another of the many IoC frameworks out there and recommended that it was pretty cool.
I wanted to learn a little more about it and to see if it would work with my original sample.
In short the simple answer was yes it does. I was able to use the same approach of using a rule to tell me which assemblies to inspect for installers (which in Autofac are very similar but implement a different interface) and then I could use my same wrappers around the container to make it nice and easy to play with.
I needed to make a couple of small changes around the internal building of the container to suit the way that Autofac works compared to Castle but there wasnt much to change at all and I quite like what it does and seems to be documented really well. The most noticable difference was for transient objects the use of a LifeTimeScope which allows you to more explicitly clean up objects. This is something I like because it is a more obvious way to trust that the developers in my team would get used to cleaning up those objects where as with Castle there is some little twists around how object disposal is managed in different scenarios. This is discussed well in this article:
You can see below how a using statement can be used to manage this with Autofac which is pretty cool
If you want to check out the autofac version of the demo its on the below link:
Thanks for checking out my article. If you liked it or found it useful that's really great. Please feel free to say hi if you bump into me at any networking events and any likes, shares or feedback on the article are really appreciated. If you really loved it you are also welcome to buy me a coffee using the button below.
All the best