Unity support fluent configuration?

Nov 22, 2008 at 11:27 PM
Most IoC containers support fluent configuration, meaning I don't have to configure anything in web.config or any other xml. Does Unity support this yet?
Nov 23, 2008 at 2:06 AM
Yes, Unity definitely supports this.  Using Unity doesn't require you to configure anything in an xml file.  You can specify registrations via code or configuration and provides a fluent interface allowing you to make several registrations in one statement.  Check out the documentation for more info.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Nov 24, 2008 at 1:01 PM
I created a screencast that walks one through the various options for registering types using the fluent interface / API on the UnityContainer without using XML:

Unity Dependency Injection IoC Screencast

Hope this helps,

Nov 24, 2008 at 2:26 PM
Edited Nov 24, 2008 at 5:24 PM
Thanks to both of you.

One thing I'm curious about is it seems like I'm required to have references to data project in my UI in order to use the fluent configuration and wire up DAO's. That reference is not something I want to do. It can be done with xml configuration without the direct reference but I would prefer to use fluent configuration. What would be nice to see is something like Registry that structuremap added and the ability to scan for Registries. This would alleviate the need for UI data references.
Nov 24, 2008 at 4:35 PM
You only need to have the EL Data block referenced if you're configuring the data access block.

Could you give a little more detail on what you're trying to do?


Nov 24, 2008 at 5:22 PM
What I meant to say was that to use fluent configuration I'm required to reference my data project in my UI.  I had a unintended declaration to EL in my web.config which caused a different problem thus I've re-phrased my other post.
Nov 24, 2008 at 6:09 PM
Edited Nov 24, 2008 at 6:10 PM
StructureMap's scan for registries can easily be created for Unity with an Extension Method similar to how I wrote a simple extension method that scans the current assembly and registers the types associated with a specific interface:

Extend Unity and UnityContainer with Extension Methods in C# 3.0

It is just an example, but with a few changes you can easily get it to look at other assemblies, etc.


Nov 24, 2008 at 7:11 PM
Ah, thank you David.