Unity 1.2 Hands-on Labs and Advertising Injectable Dependencies
Hand-on Labs for Unity 1.2 are now available (via J.D. Meier). Unity is a very simple and lightweight dependency injection container.
One of the features of Unity is the ability to define type aliases that allow you to define the full type name once and then use an alias to refer to it elsewhere in the configuration. For example:
<unity> <typeAliases> <typeAlias alias="IClipboard" type="MyApplication.Services.Clipboard.IClipboard, MyApplication" /> </typeAliases> </unity>
While working through the examples in the hands-on labs it occurred to me that this is a good way of advertising the different dependencies that can be injected. By defining a type alias for each of the dependencies that can be injected (both mandatory and optional) then developers wanting to extend your application can easily see the available dependencies.
For example:
<unity> <typeAliases> <!--Mandatory--> <typeAlias alias="IClipboard" type="MyApplication.Services.Clipboard.IClipboard, MyApplication" /> <typeAlias alias="IStore" type="MyApplication.Services.Store.IStore, MyApplication" /> <!--Optional--> <typeAlias alias="ILogger" type="MyApplication.Services.Logger.ILogger, MyApplication" /> </typeAliases> </unity>