Created
December 26, 2015 08:43
-
-
Save miklund/f57921afa48f40fe12b3 to your computer and use it in GitHub Desktop.
2009-05-25 Part 2: Dependency injection with Unity and XML configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Part 2: Dependency injection with Unity and XML configuration | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2009/05/25/part-2-dependency-injection-with-unity-and-xml-configuration.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<type type="RssDocument" mapTo="RssDocument" name="Movies"> | |
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, | |
Microsoft.Practices.Unity.Configuration"> | |
<constructor> | |
<param name="version" parameterType="System.String"> | |
<value value="2.0" type="System.String" /> | |
</param> | |
<param name="channelGenerators" parameterType="RssChannelGeneratorArray"> | |
<array> | |
<dependency name="MovieList" /> | |
</array> | |
</param> | |
</constructor> | |
</typeConfig> | |
</type> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<type type="RssChannelGenerator" mapTo="Kino.Lib.Rss.RssDirectoryGenerator, Kino.Lib" name="MovieList"> | |
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, | |
Microsoft.Practices.Unity.Configuration"> | |
<constructor> | |
<param name="title" parameterType="System.String"> | |
<value value="Movies" type="System.String" /> | |
</param> | |
<param name="link" parameterType="System.String"> | |
<value value="http://mint.litemedia.se" type="System.String" /> | |
</param> | |
<param name="description" parameterType="System.String"> | |
<value value="Sharing of movies" type="System.String" /> | |
</param> | |
<param name="documentation" parameterType="System.String"> | |
<value value="http://blogs.law.harvard.edu/tech/rss" type="System.String" /> | |
</param> | |
<param name="managingEditor" parameterType="System.String"> | |
<value value="[email protected]" type="System.String" /> | |
</param> | |
<param name="webMaster" parameterType="System.String"> | |
<value value="[email protected]" type="System.String" /> | |
</param> | |
<param name="basePath" parameterType="System.String"> | |
<value value="C:\Movies" type="System.String" /> | |
</param> | |
<param name="searchPattern" parameterType="SearchPatterns"> | |
<array> | |
<value value="*.wmv" type="System.String" /> | |
<value value="*.avi" type="System.String" /> | |
<value value="*.mpg" type="System.String" /> | |
</array> | |
</param> | |
</constructor> | |
</typeConfig> | |
</type> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public UnityContainer GetContainer(string name) | |
{ | |
if (configurationSection == null) | |
throw new InvalidOperationException("No unity configuration was found, could not instansiate container"); | |
var container = new UnityContainer(); | |
UnityContainerElement containerConfiguration = configurationSection.Containers[name]; | |
if (containerConfiguration == null) | |
throw new ConfigurationErrorsException("No unity configuration for " + name + " was found"); | |
containerConfiguration.Configure(container); | |
return container; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<configSections> | |
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=1.2.0.0" /> | |
</configSections> | |
<unity configSource="Unity.config" /> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment