• Home
  • Posts RSS
  • Comments RSS
  • Edit
Blue Orange Green Pink Purple

Matt Linder

My Photo Much like Hector Salamanca, I believe family is everything. I run and cycle sometimes, too. I spend the majority of my week days implementing a solution, or solving problems at a computer, aided by a trusty bag of almond m&ms.

Google Accounts Multiple Sign-In

Google accounts now offers multiple sign-in. The feature may have to be enabled if you have not done so already for each account you plan to use...

Read More

Unity config changes for 2.1


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:


<?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>
Read More 0 comments | Posted by Matt Linder edit post

0 comments



Post a Comment

Newer Post Older Post Home

Matt Linder

  • About

      Former scoutmaster, soccer coach, long distance runner turned donut connoisseur and father of five with a passion for learning technology and solving technical problems!

      View Matt Linder's profile on LinkedIn
    • About Me

      My photo
      Matt Linder
      South Carolina native, lover of peanut butter and donuts, and web developer.
      View my complete profile

      Professional Matt Linder

      Matt Linder's public blog.

      Blog Archive

      • ►  2015 (1)
        • ►  August (1)
      • ►  2013 (1)
        • ►  October (1)
      • ▼  2012 (11)
        • ▼  October (1)
          • Unity config changes for 2.1
        • ►  July (2)
        • ►  June (1)
        • ►  April (2)
        • ►  March (5)

      Achievements Unlocked

      fitness apps fitness apps fitness apps fitness apps
    • Search






      • Home
      • Posts RSS
      • Comments RSS
      • Edit

      © Copyright Professional Matt Linder. All rights reserved.

      Designed by FTL Wordpress Themes | Bloggerized by FalconHive.com | Blogger Templates
      brought to you by Smashing Magazine

      Back to Top