Unity is a great tool from the patterns and practices team at Microsoft. Its an asset to loosely couple classes for different patterns and architectures.
After running into a snag with Unity, I decided to run through the demo available from the microsoft download. I have installed VS 2012 and love the new features.
Unfortunately, the 2008 demo has the old style configuration schema, which breaks when you reference the new Unity assemblies. After a few minutes of reviewing the documentation I got it t work. I will include the new format here in case anyone else needs it.
Original:
After running into a snag with Unity, I decided to run through the demo available from the microsoft download. I have installed VS 2012 and love the new features.
Unfortunately, the 2008 demo has the old style configuration schema, which breaks when you reference the new Unity assemblies. After a few minutes of reviewing the documentation I got it t work. I will include the new format here in case anyone else needs it.
Original:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>
<unity>
<typeAliases>
<typeAlias alias="int" type="System.Int32, mscorlib" />
<typeAlias alias="singleton"
type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="transient"
type="Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="IMachineDisplay"
type="SlotMachine.IMachineDisplay, SlotMachine" />
<typeAlias alias="ISpinner"
type="SlotMachine.ISpinner, SlotMachine" />
<typeAlias alias="IWinningsCalculator"
type="SlotMachine.IWinningsCalculator, SlotMachine" />
</typeAliases>
<containers>
<container>
<types>
<type type="IMachineDisplay" mapTo="SlotMachine.ConsoleDisplay, SlotMachine">
<lifetime type="singleton" />
</type>
<type type="ISpinner" mapTo="SlotMachine.SimpleSpinner, SlotMachine">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
<property name="Display" propertyType="IMachineDisplay" />
</typeConfig>
</type>
<type type="IWinningsCalculator" mapTo="SlotMachine.AirportWinningsCalculator, SlotMachine" />
<type type="SlotMachine.SlotMachine, SlotMachine">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
<constructor>
<param name="id" parameterType="int">
<value value="37" type="int" />
</param>
<param name="display" parameterType="IMachineDisplay">
<dependency />
</param>
<param name="spinner" parameterType="ISpinner">
<dependency />
</param>
<param name="calculator" parameterType="IWinningsCalculator">
<dependency name="debug"/>
</param>
</constructor>
</typeConfig>
</type>
</types>
</container>
<container name="child">
<types>
<type type="IMachineDisplay" mapTo="SlotMachine.ConsoleDisplay, SlotMachine">
<lifetime type="transient" />
</type>
</types>
</container>
</containers>
</unity>
</configuration>
Updated:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/> </configSections> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity" <alias alias="int" type="System.Int32, mscorlib" /> <alias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" /> <alias alias="transient" type="Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity" /> <alias alias="IMachineDisplay" type="SlotMachine.IMachineDisplay, SlotMachine" /> <alias alias="ISpinner" type="SlotMachine.ISpinner, SlotMachine" /> <alias alias="IWinningsCalculator" type="SlotMachine.IWinningsCalculator, SlotMachine" /> <containers> <container> <register type="IMachineDisplay" mapTo="SlotMachine.ConsoleDisplay, SlotMachine"> <lifetime type="singleton" /> </register> <register type="ISpinner" mapTo="SlotMachine.SimpleSpinner, SlotMachine"> <property name="Display" dependencyType="IMachineDisplay" /> </register> <register type="IWinningsCalculator" mapTo="SlotMachine.AirportWinningsCalculator, SlotMachine" /> <register type="SlotMachine.SlotMachine, SlotMachine"> <constructor> <param name="id" value="37" > </param> <param name="display" > <dependency /> </param> <param name="spinner"> <dependency /> </param> <param name="calculator"> <dependency name="debug"/> </param> </constructor> </register> </container> <container name="child"> <register type="IMachineDisplay" mapTo="SlotMachine.ConsoleDisplay, SlotMachine"> <lifetime type="transient" /> </register> </container> </containers> </unity> </configuration>