<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>build broken &#187; HowTo</title>
	<atom:link href="http://blog.aztec-project.org/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.aztec-project.org</link>
	<description>but we can fix it! Sometimes :)</description>
	<lastBuildDate>Fri, 11 Jun 2010 12:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Anonyme Datentypen</title>
		<link>http://blog.aztec-project.org/2009/06/10/anonyme-datentypen/</link>
		<comments>http://blog.aztec-project.org/2009/06/10/anonyme-datentypen/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 09:43:40 +0000</pubDate>
		<dc:creator>Andreas Seebauer</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://blog.aztec-project.org/?p=175</guid>
		<description><![CDATA[Anonyme Datentypen sind Klassen, die erst beim Kompilieren durch den Compiler definiert werden. Die Klassendefinition befindet sich also nicht im Quellcode. Die anonymen Datentypen leiten wie jedes andere Referenzobjekt von der Klasse object ab. Sie sind als reine Datenklassen gedacht und es können keine weiteren Methoden oder Events hinzugefügt werden. Obwohl der anonyme Datentyp auf [...]]]></description>
			<content:encoded><![CDATA[<p>Anonyme Datentypen sind Klassen, die erst beim Kompilieren durch den Compiler definiert werden. Die Klassendefinition befindet sich also nicht im Quellcode. Die anonymen Datentypen leiten wie jedes andere Referenzobjekt von der Klasse object ab. Sie sind als reine Datenklassen gedacht und es können keine weiteren Methoden oder Events hinzugefügt werden. Obwohl der anonyme Datentyp auf Quellcodeebene noch nicht definiert ist, muss dank Visual Studio nicht auf die Intellisense verzichtet werden.</p>
<p>Definiert und intstanziert werden sie mit new und einem Objektinitialisierer:</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;"><span style="color: blue;">    var</span> mitarbeiter = <span style="color: blue;">new</span> { Name = <span style="color: #a31515;">"Müller"</span>, Abteilung = <span style="color: #a31515;">"IT"</span> };</pre>
</div>
<p>var ist der implizite Typ und <strong>nicht </strong>der anonyme Datentyp. Er fungiert hier lediglich als container für die Instanz des anonymen Datentyps, die mit new {} erzeugt wird.</p>
<p>Gibt man keinen Namen für die Properties an, werden die Namen der Properties verwendet, mit denen initialisiert wird.</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;">    <span style="color: blue;">var</span> abteilung = <span style="color: blue;">new</span> { Abteilungsname = <span style="color: #a31515;">"IT"</span> };</pre>
<pre style="margin: 0px;">    <span style="color: blue;">var</span> mitarbeiter = <span style="color: blue;">new</span> { Name = <span style="color: #a31515;">"Müller"</span>, abteilung.Abteilungsname };</pre>
<pre style="margin: 0px;">    <span style="color: #2b91af;">Console</span>.WriteLine(mitarbeiter.Abteilungsname);</pre>
</div>
<p>Wenn man mit Werten initialisiert, muss ein Name angegeben werden.</p>
<p>Anonyme Datentypen bieten sich an, wenn man Abfragen mit Linq ausführt und entweder nur eine Teilmenge des ursprünglichen Objekts braucht, oder wenn man ein Objekt erweitern will, ohne extra eine neue Klasse zu definieren.</p>
<p>Hier ein Beispiel aus einem Castle Monorail Projekt, in dem eine erweiterte Liste an eine vm gegeben wird, ohne eine neue Klasse definieren zu müssen. Es soll dabei eine Liste erstellt werden, in der die Mitarbeiter mit ihrem Horoskop verknüpft werden :</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black;">
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black;">
<pre style="margin: 0px;">    <span style="color: blue;">public</span> <span style="color: blue;">void</span> Action() {</pre>
<pre style="margin: 0px;">        <span style="color: #2b91af;">IList</span>&lt;<span style="color: #2b91af;">Mitarbeiter</span>&gt; mitarbeiterListe = m_service.GetMitarbeiter();</pre>
<pre style="margin: 0px;">        <span style="color: blue;">var</span> mitarbeiterMitHoroskopListe = (<span style="color: blue;">from</span> mitarbeiter <span style="color: blue;">in</span> mitarbeiterListe</pre>
<pre style="margin: 0px;">            <span style="color: blue;">select</span> <span style="color: blue;">new</span> { Mitarbeiter = mitarbeiter,</pre>
<pre style="margin: 0px;">                         Horoskop = GetHoroskop(mitarbeiter.Geburtsdatum) });</pre>
<pre style="margin: 0px;">        PropertyBag[<span style="color: #a31515;">"mitarbeiterMitHoroskopListe"</span>] = mitarbeiterMitHoroskopListe;</pre>
<pre style="margin: 0px;">    }</pre>
</div>
</div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.aztec-project.org%2F2009%2F06%2F10%2Fanonyme-datentypen%2F&amp;title=Anonyme%20Datentypen"><img src="http://blog.aztec-project.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.aztec-project.org/2009/06/10/anonyme-datentypen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamisches Laden von Assemblies</title>
		<link>http://blog.aztec-project.org/2009/06/05/dynamisches-laden-von-assemblies/</link>
		<comments>http://blog.aztec-project.org/2009/06/05/dynamisches-laden-von-assemblies/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 19:57:46 +0000</pubDate>
		<dc:creator>Thomas Christian</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Assembly]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://blog.aztec-project.org/?p=50</guid>
		<description><![CDATA[In diesem Blog-Post möchte ich kurz erläutern, wie ich mit dem Problem des dynamischen Ladens von Assemblies umgegangen bin. Vor einiger Zeit stand ich vor dem Problem, dass ich zur Laufzeit Assemblies austauschen wollte. Grund dafür war, dass ich eine Host-Applikation hatte, die Plug-Ins verwendet. Jetzt wollte ich bestehende Plug-Ins während der Laufzeit austauschen oder [...]]]></description>
			<content:encoded><![CDATA[<p>In diesem Blog-Post möchte ich kurz erläutern, wie ich mit dem Problem des dynamischen Ladens von Assemblies umgegangen bin.</p>
<p>Vor einiger Zeit stand ich vor dem Problem, dass ich zur Laufzeit Assemblies austauschen wollte. Grund dafür war, dass ich eine Host-Applikation hatte, die Plug-Ins verwendet. Jetzt wollte ich bestehende Plug-Ins während der Laufzeit austauschen oder neue Plug-Ins hinzufügen ohne die Host-Applikation zu beenden. Dazu hatte ich ein Verzeichnis in dem sich, außer den Plug-Ins, alle Assemblies befanden. Die Plug-Ins selbst befanden sich in einem eigenen Unterverzeichnis. Selbst wenn die Plug-Ins von der Host-Applikation nicht mehr verwendet wurden, war es nicht möglich, diese Assemblies zu löschen.</p>
<p>Im Normalfall ist es so, dass sobald eine Assembly von einer Applikation verwendet wird, eine Referenz auf diese existiert. Diese Referenz wird leider erst gelöscht, wenn die ganze Applikation beendet wird.</p>
<p>Bei dem dynamischen Laden von Assemblies wird die zu ladende Assembly geöffnet, ausgelesen und dann geschlossen. Aus den ausgelesenen Bytes wird dann mittels Reflection eine Assembly im Arbeitsspeicher erzeugt. Auf die lokale Assembly hängt somit keine Referenz und es ist möglich diese zu löschen.</p>
<p>Meine Umsetzung sieht folgendermaßen aus:</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: #2b91af;">    2</span> <span style="color: blue;">public</span> IList&lt;Plugin&gt; GetPlugins(<span style="color: blue;">string</span> assemblyName) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    3</span>     Assembly assembly;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    4</span>     IList&lt;Plugin&gt; pluginList = <span style="color: blue;">new</span> IList&lt;Plugin&gt;();</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    5</span>     <span style="color: blue;">try</span> {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    6</span>         <span style="color: blue;">byte</span>[] byteAssembly = File.ReadAllBytes(assemblyName);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    7</span>         assembly = Assembly.Load(byteAssembly);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    8</span>     } <span style="color: blue;">catch</span> (Exception ex) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    9</span>         log.Error(ex);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   10</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   11</span>     <span style="color: blue;">try</span> {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   12</span>         <span style="color: blue;">if</span> (assembly != <span style="color: blue;">null</span>) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   13</span>             Type[] assemblyTypes = assembly.GetTypes();</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   14</span>             <span style="color: blue;">foreach</span> (Type assemblyTyp <span style="color: blue;">in</span> assemblyTypes) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   15</span>                 <span style="color: blue;">if</span> (<span style="color: blue;">typeof</span>(Plugin).IsAssignableFrom(assemblyTyp)) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   16</span>                     plugin = (Plugin)assembly.CreateInstance(assemblyTyp</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   17</span>                                                                 .FullName);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   18</span>                     <span style="color: blue;">if</span> (plugin != <span style="color: blue;">null</span>) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   19</span>                         pluginList.Add(plugin);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   20</span>                     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   21</span>                 }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   22</span>             }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   23</span>         }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   24</span>     } <span style="color: blue;">catch</span> (ReflectionTypeLoadException ex) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   25</span>         log.Error(ex);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   26</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   27</span>     <span style="color: blue;">return</span> pluginList;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   28</span> }</pre>
</div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.aztec-project.org%2F2009%2F06%2F05%2Fdynamisches-laden-von-assemblies%2F&amp;title=Dynamisches%20Laden%20von%20Assemblies"><img src="http://blog.aztec-project.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.aztec-project.org/2009/06/05/dynamisches-laden-von-assemblies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Umsetzung des Plug-In-Patterns</title>
		<link>http://blog.aztec-project.org/2009/06/05/umsetzung-des-plug-in-patterns/</link>
		<comments>http://blog.aztec-project.org/2009/06/05/umsetzung-des-plug-in-patterns/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 19:45:57 +0000</pubDate>
		<dc:creator>Thomas Christian</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Architektur]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Plug-In]]></category>

		<guid isPermaLink="false">http://blog.aztec-project.org/?p=5</guid>
		<description><![CDATA[In meinem ersten Blog-Post möchte ich euch in vereinfachter Form meine Umsetzung des Plug-In-Patterns vorstellen. Voraussetzungen für dieses Pattern sind: eine Host-Applikation die das Plug-In laden möchte ein Plug-In welches es zu laden gilt und die Schnittstellen Plugin und IHost Zu allererst brauchen wir eine gemeinsame Schnittstelle, die sowohl vom Plug-In als auch vom Host [...]]]></description>
			<content:encoded><![CDATA[<p>In meinem ersten Blog-Post möchte ich euch in vereinfachter Form meine Umsetzung des Plug-In-Patterns vorstellen.<br />
Voraussetzungen für dieses Pattern sind:</p>
<ul>
<li> eine Host-Applikation die das Plug-In laden möchte</li>
<li> ein Plug-In welches es zu laden gilt</li>
<li> und die Schnittstellen Plugin und IHost</li>
</ul>
<p>Zu allererst brauchen wir eine gemeinsame Schnittstelle, die sowohl vom Plug-In als auch vom Host (die Applikation welche das Plug-In verwenden soll) benutzt werden soll. Über diese Schnittstelle kommuniziert der Host mit dem Plug-In.<br />
Es würde sich das Interface IPlugIn anbieten. In meinem Fall verwende ich allerdings kein Interface sondern eine abstrakte Klasse, da ich bereits Logik direkt in die Schnittstelle implementieren möchte. In meinem Fall heißt die abstrakte Klasse einfach nur Plugin. Im weiteren Verlauf werde ich zu meiner abstrakten Klasse Schnittstelle sagen.</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: #2b91af;">    1</span> <span style="color: blue;">public</span> <span style="color: blue;">abstract</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Plugin</span> {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    2</span>     <span style="color: blue;">private</span> IHost m_host;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    3</span>     <span style="color: blue;">public</span> Plugin(<span style="color: blue;">string</span> name) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    4</span>         Name = name;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    5</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    6</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    7</span>     <span style="color: blue;">public</span> <span style="color: blue;">string</span> Name { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    8</span>     <span style="color: blue;">public</span> <span style="color: blue;">string</span> Author { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    9</span>     <span style="color: blue;">public</span> <span style="color: blue;">string</span> Version { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   10</span>     <span style="color: blue;">public</span> <span style="color: blue;">bool</span> IsRegistered { <span style="color: blue;">get</span>; <span style="color: blue;">private</span> <span style="color: blue;">set</span>; }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   11</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   12</span>     <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   13</span>     <span style="color: gray;">///</span><span style="color: green;"> Setzt oder gibt die Host-Application.</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   14</span>     <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   15</span>     <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;value&gt;</span><span style="color: green;">Host-Application.</span><span style="color: gray;">&lt;/value&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   16</span>     <span style="color: blue;">public</span> IHost Host {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   17</span>         <span style="color: blue;">get</span> { <span style="color: blue;">return</span> m_host; }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   18</span>         <span style="color: blue;">set</span> {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   19</span>             <span style="color: blue;">if</span> (<span style="color: blue;">value</span> != <span style="color: blue;">null</span>) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   20</span>                 <span style="color: blue;">if</span> (m_host == <span style="color: blue;">null</span>) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   21</span>                     m_host = <span style="color: blue;">value</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   22</span>                     <span style="color: blue;">if</span> (m_host.Register(<span style="color: blue;">this</span>)) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   23</span>                         IsRegistered = <span style="color: blue;">true</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   24</span>                     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   25</span>                 }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   26</span>             } <span style="color: blue;">else</span> {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   27</span>                 <span style="color: blue;">if</span> (m_host.Unregister(<span style="color: blue;">this</span>)) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   28</span>                     m_host = <span style="color: blue;">value</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   29</span>                     IsRegistered = <span style="color: blue;">false</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   30</span>                 }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   31</span>             }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   32</span>         }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   33</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   34</span> }</pre>
</div>
<p>Ich glaube, der Aufbau der Schnittstelle Plugin sollte bis auf die Property “Host” klar sein. Wie man sieht, benötigt man bei diesem Pattern zusätzlich zur Schnittstelle Plugin noch das IHost-Interface.<br />
Dieses Interface ist direkter Bestandteil der Schnittstelle Plugin. Nun kann man sich natürlich die Frage stellen, warum das Plug-In den Host kennen muss und somit von diesem abhängig ist.</p>
<p>Zum einen ist es in der Regel so, dass ein Plug-In für nur einen Host entwickelt wird und zum anderen wollte ich dem Host gewisse Richtlinien zum Registrieren und Lösen des Plug-Ins vorgeben.</p>
<p>Das Interface IHost sieht folgendermaßen aus:</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: #2b91af;">    1</span> <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IHost</span> {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    2</span>     <span style="color: blue;">bool</span> Register(Plugin plugin);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    3</span>     <span style="color: blue;">bool</span> Unregister(Plugin plugin);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    4</span> }</pre>
</div>
<p>Dieses Interface muss von der Host-Applikation implementiert werden, damit sich das Plug-In am Host registrieren kann. Im letzten Satz habe ich es schon angedeutet. Nicht der Host registriert das Plug-In bei sich, sondern das Plug-In registriert sich am Host. Durch das setzen der Property Plugin.Host wird die Methode Register oder Unregister vom Plug-In aufgerufen, welche der Host implementiert.</p>
<p>Eine vereinfachte Darstellung der Implementierung des IHost -Interfaces sieht folgendermaßen aus:</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: #2b91af;">    1</span> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">HostApplication</span> : IHost {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    2</span>     <span style="color: blue;">private</span> List&lt;Plugin&gt; m_pluginList;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    3</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    4</span>     <span style="color: green;">//Konstruktor</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    5</span>     <span style="color: blue;">public</span> HostApplication() {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    6</span>         m_pluginList = <span style="color: blue;">new</span> List&lt;Plugin&gt;();</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    7</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    8</span>         <span style="color: green;">//Lädt alle verfügbaren Plug-Ins zb. aus einem Verzeichnis</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">    9</span>         List&lt;Plugin&gt; plugins = GetPlugins();</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   10</span>         <span style="color: blue;">foreach</span> (Plugin plugin <span style="color: blue;">in</span> plugins) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   11</span>             <span style="color: green;">//ruft implizit die IHost.Register-Methode auf</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   12</span>             plugin.Host = <span style="color: blue;">this</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   13</span>         }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   14</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   15</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   16</span>     <span style="color: blue;">public</span> <span style="color: blue;">void</span> ShowPlugins() {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   17</span>         <span style="color: blue;">foreach</span> (Plugin plugin <span style="color: blue;">in</span> m_pluginList) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   18</span>             <span style="color: green;">//Ausgabe der Namen aller am Host registrierten Plug-Ins</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   19</span>             Console.WriteLine(plugin.Name);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   20</span>         }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   21</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   22</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   23</span>     <span style="color: blue;">public</span> <span style="color: blue;">void</span> UnloadPlugins() {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   24</span>         <span style="color: blue;">foreach</span> (Plugin plugin <span style="color: blue;">in</span> m_pluginList) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   25</span>             <span style="color: green;">//ruft implizit die IHost.Unregister-Methode auf</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   26</span>             plugin.Host = <span style="color: blue;">null</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   27</span>         }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   28</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   29</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   30</span> <span style="color: blue;">    #region</span> IHost-Implementierung</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   31</span>     <span style="color: blue;">public</span> <span style="color: blue;">bool</span> Register(Plugin plugin) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   32</span>         <span style="color: blue;">if</span> (!m_pluginList.Contains(plugin)) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   33</span>             m_pluginList.Add(plugin);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   34</span>             <span style="color: blue;">return</span> <span style="color: blue;">true</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   35</span>         }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   36</span>         <span style="color: blue;">return</span> <span style="color: blue;">false</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   37</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   38</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   39</span>     <span style="color: blue;">public</span> <span style="color: blue;">bool</span> Unregister(Plugin plugin) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   40</span>         <span style="color: blue;">if</span> (m_pluginList.Contains(plugin)) {</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   41</span>             m_pluginList.Remove(plugin);</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   42</span>             <span style="color: blue;">return</span> <span style="color: blue;">true</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   43</span>         }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   44</span>         <span style="color: blue;">return</span> <span style="color: blue;">false</span>;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   45</span>     }</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   46</span> <span style="color: blue;">    #endregion</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">   47</span> }</pre>
</div>
<p>Das Registrieren und Lösen der Plug-Ins könnte man nun noch in einen Plug-In-Manager auslagern, worauf ich in diesem Blog allerdings verzichten möchte.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.aztec-project.org%2F2009%2F06%2F05%2Fumsetzung-des-plug-in-patterns%2F&amp;title=Umsetzung%20des%20Plug-In-Patterns"><img src="http://blog.aztec-project.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.aztec-project.org/2009/06/05/umsetzung-des-plug-in-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

