OpenSource http://blogs.ugidotnet.org/bmatte/category/OpenSource.aspx OpenSource it-IT Matteo Baglini Subtext Version 2.6.0.0 FluentNHibernate, UserType e UserTypeConvention http://blogs.ugidotnet.org/bmatte/archive/2009/10/02/fluentnhibernate-usertype-e-usertypeconvention.aspx <p>Sviluppando applicazioni con <a href="http://nhforge.org/" target="_blank">NHibernate</a> capita spesso di avere l’esingenza di creare uno UserType per mappare in modo particolare una classe. In questo post non mi interessa descrivere come realizzare uno UserType , basta fare una <a href="http://www.google.it/search?hl=it&amp;client=firefox-a&amp;rls=org.mozilla%3Ait%3Aofficial&amp;hs=V43&amp;q=nhibernate+usertype&amp;btnG=Cerca&amp;meta=" target="_blank">ricerca su google</a> per “essere sommersi” di guide, quello che voglio mostrare è la semplicità di mapping di uno UserType tramite <a href="http://fluentnhibernate.org/" target="_blank">FluentNHibernate</a> e la classe generica <a href="http://fluentnhibernate.org/api/FluentNHibernate.Conventions/UserTypeConvention%601.htm" target="_blank">UserTypeConvention&lt;TUserType&gt;.</a> Supponiamo di avere le classi Money e MoneyUserType, rispettivamente la classe da persistere e la definizione dello UserType, il mapping consiste semplicemente in qusto snippet di codice.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">public</span> <span class="kwrd">class</span> MoneyUserTypeConvention : UserTypeConvention&lt;MoneyUserType&gt;</pre> <pre><span class="lnum"> 2: </span>{</pre> <pre class="alt"><span class="lnum"> 3: </span>}</pre> </div> <div class="csharpcode"> </div> <style type="text/css"><![CDATA[ .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }]]></style> <p>Il passo successivo è <a href="http://wiki.fluentnhibernate.org/Conventions" target="_blank">configuare opportunamente FluentNHibernate</a>. La curiosità però mi ha spinto ad indagare tramite Reflector cosa fa questa classe.</p> <p><a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/bmatte/WindowsLiveWriter/FluentNHibernateUserTypeeUserTypeConvent_E868/post1.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="post1" border="0" alt="post1" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/bmatte/WindowsLiveWriter/FluentNHibernateUserTypeeUserTypeConvent_E868/post1_thumb.png" width="244" height="222" /></a> </p> <p>Dall’immagine è chiaro che FluentNHibernate nel metodo Accept, utilizzato per capire se applicare quella determinata convenzione, crea una istanza di TUserType. Se abbiamo un numero elevato di UserType avremo anche un numero elevato di chiamate al metedo CreateInstance con conseguenti problemi di performance nella fase di creazione del mapping. Per ovviare a questo “problema” basta effettuare l’override del metodo e specificare esplicitamente il criterio di uguaglianza.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">public</span> <span class="kwrd">class</span> MoneyUserTypeConvention : UserTypeConvention&lt;MoneyUserType&gt;</pre> <pre><span class="lnum"> 2: </span>{</pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">bool</span> Accept(System.Type type)</pre> <pre><span class="lnum"> 4: </span> {</pre> <pre class="alt"><span class="lnum"> 5: </span> <span class="kwrd">return</span> type == <span class="kwrd">typeof</span> (Money);</pre> <pre><span class="lnum"> 6: </span> }</pre> <pre class="alt"><span class="lnum"> 7: </span>}</pre> </div> <p> </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f24d655b-c25c-43d1-abcb-800f8043d7e1" class="wlWriterEditableSmartContent">Technorati Tag: <a href="http://technorati.com/tags/NHibernate" rel="tag">NHibernate</a>,<a href="http://technorati.com/tags/FluentNHibernate" rel="tag">FluentNHibernate</a>,<a href="http://technorati.com/tags/UserType" rel="tag">UserType</a>,<a href="http://technorati.com/tags/UserTypeConvention" rel="tag">UserTypeConvention</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/97161.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2009/10/02/fluentnhibernate-usertype-e-usertypeconvention.aspx Fri, 02 Oct 2009 17:31:39 GMT http://blogs.ugidotnet.org/bmatte/archive/2009/10/02/fluentnhibernate-usertype-e-usertypeconvention.aspx#feedback 1 http://blogs.ugidotnet.org/bmatte/comments/commentRss/97161.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/97161.aspx WPF Functional Testing With White http://blogs.ugidotnet.org/bmatte/archive/2008/12/18/wpf-functional-testing-with-white.aspx <p>(@ <a href="http://blogs.ugidotnet.org/dsantarelli" target="_blank">Dario</a>: accetto la sfida!!! <img alt="smile_teeth" src="http://spaces.live.com/rte/emoticons/smile_teeth.gif" /> )</p> <p>Nel mio <a href="http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/wpf-ui-test-framework.aspx" target="_blank">ultimo post</a> ho annunciato il rilascio di un framework per effettuare test funzionali per applicazioni desktop in maniera del tutto automatica. <a href="http://blogs.ugidotnet.org/dsantarelli" target="_blank">Dario</a> ha accettato la mia <a href="http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/wpf-ui-test-framework.aspx#1405390" target="_blank">richiesta</a> rispondendo con un bel <a href="http://blogs.ugidotnet.org/dsantarelli/archive/2008/12/17/testapi-e-input-injection.aspx" target="_blank">post su TestApi e Input Injection</a>. Tutto ciò mi ha messo voglia di provare a rifare il solito test da lui proposto, però utilizzando <a href="http://www.codeplex.com/white" target="_blank">white</a>, così possiamo confrontare i due framework. Cominciamo!!</p> <p>Prima di tutto lo screenshot della mia applicazione, non è proprio identica a quella di Dario, ma va benissimo!</p> <p><a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/bmatte/WindowsLiveWriter/UIFunctionalTestingWithWhite_12787/ui%20test_2.png" target="_blank"><img title="ui test" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="232" alt="ui test" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/bmatte/WindowsLiveWriter/UIFunctionalTestingWithWhite_12787/ui%20test_thumb.png" width="384" border="0" /></a> </p> <p>Come sappiamo, lo scopo del test è quello di:</p> <ol> <li>Lanciare l'applicazione </li> <li>Selezione della modalità di filtraggio (ovvero selezione di un item della ComboBox) </li> <li>Inserimento della filterExpression (typing nella TextBox) </li> <li>Click del Button di ricerca </li> <li>Valutazione dei risultati nella ListBox </li> </ol> <p>Niente di più facile!! <img alt="smile_wink" src="http://spaces.live.com/rte/emoticons/smile_wink.gif" /> Come per le <a href="http://www.codeplex.com/TestApi" target="_blank">TestApi</a>, per prima cosa nello XAML dobbiamo impostare per ogni elemento interessato l’Attached Properties <a href="http://msdn.microsoft.com/en-us/library/system.windows.automation.automationproperties.automationid.aspx" target="_blank">AutomationProperties.AutomationId</a>, successivamente aggiungiamo un progetto di tipo Class Library per i test. Aggiungiamo come reference al progetto le librerie Core.dll, White.NUnit.dll e nunit.framework.dll, quest’ultima libreria viene fornita insieme ai binari di <a href="http://www.codeplex.com/white" target="_blank">white</a> però in realtà fa parte del framework <a href="http://www.nunit.org/" target="_blank">NUnit</a>. Adesso non ci resta che aggiungere una nuava classe e scrivere il metodo di test come mostrato nel seguente snippet:</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>[TestFixture]</pre> <pre><span class="lnum"> 2: </span><span class="kwrd">public</span> <span class="kwrd">class</span> MainWindowTests</pre> <pre class="alt"><span class="lnum"> 3: </span>{</pre> <pre><span class="lnum"> 4: </span> <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> path = <span class="str">@"C:\…\WhiteDemoWithWpf.exe"</span>;</pre> <pre class="alt"><span class="lnum"> 5: </span> </pre> <pre><span class="lnum"> 6: </span> [Test]</pre> <pre class="alt"><span class="lnum"> 7: </span> <span class="kwrd">public</span> <span class="kwrd">void</span> When_click_search_should_filter_loaded_data_by_selected_mode_and_typed_expression()</pre> <pre><span class="lnum"> 8: </span> {</pre> <pre class="alt"><span class="lnum"> 9: </span> <span class="kwrd">string</span> productNameToMatch = <span class="str">"Chang"</span>;</pre> <pre><span class="lnum"> 10: </span> </pre> <pre class="alt"><span class="lnum"> 11: </span> <span class="rem">//Esecuzione dell'applicazione</span></pre> <pre><span class="lnum"> 12: </span> var application = Application.Launch(path);</pre> <pre class="alt"><span class="lnum"> 13: </span> </pre> <pre><span class="lnum"> 14: </span> <span class="rem">//Ottengo la Window e verifico che non sia Null</span></pre> <pre class="alt"><span class="lnum"> 15: </span> var window = application.GetWindow(<span class="str">"MainWindow"</span>, InitializeOption.NoCache);</pre> <pre><span class="lnum"> 16: </span> Assert.That(window,Is.Not.Null);</pre> <pre class="alt"><span class="lnum"> 17: </span> </pre> <pre><span class="lnum"> 18: </span> <span class="rem">//Seleziono un elemento della ComboBox</span></pre> <pre class="alt"><span class="lnum"> 19: </span> var lstFilterCriteria = window.Get&lt;ComboBox&gt;(<span class="str">"lstFilterCriteria"</span>);</pre> <pre><span class="lnum"> 20: </span> lstFilterCriteria.Select(3);</pre> <pre class="alt"><span class="lnum"> 21: </span> </pre> <pre><span class="lnum"> 22: </span> <span class="rem">//Scrivo il Product Name per il test</span></pre> <pre class="alt"><span class="lnum"> 23: </span> var txtProductName = window.Get&lt;TextBox&gt;(<span class="str">"txtProductName"</span>);</pre> <pre><span class="lnum"> 24: </span> txtProductName.Text = productNameToMatch;</pre> <pre class="alt"><span class="lnum"> 25: </span> </pre> <pre><span class="lnum"> 26: </span> <span class="rem">//Clicco il Button per effettuare la ricerca</span></pre> <pre class="alt"><span class="lnum"> 27: </span> var btnFilterProducts = window.Get&lt;Button&gt;(<span class="str">"btnFilterProducts"</span>);</pre> <pre><span class="lnum"> 28: </span> btnFilterProducts.Click();</pre> <pre class="alt"><span class="lnum"> 29: </span> </pre> <pre><span class="lnum"> 30: </span> <span class="rem">//Verifico che il numero totale di elementi della lista sia 1</span></pre> <pre class="alt"><span class="lnum"> 31: </span> var listViewProducts = window.Get&lt;ListView&gt;(<span class="str">"listViewProducts"</span>);</pre> <pre><span class="lnum"> 32: </span> Assert.That(listViewProducts.Rows.Count, Is.EqualTo(1));</pre> <pre class="alt"><span class="lnum"> 33: </span> </pre> <pre><span class="lnum"> 34: </span> <span class="rem">//Verifico il contenuto della cella contenente </span></pre> <pre class="alt"><span class="lnum"> 35: </span> <span class="rem">//il risultato della ricerca con il Product Name per il test</span></pre> <pre><span class="lnum"> 36: </span> var cell = listViewProducts.Rows[0].Cells[0];</pre> <pre class="alt"><span class="lnum"> 37: </span> Assert.That(cell.Text, Is.EqualTo(productNameToMatch));</pre> <pre><span class="lnum"> 38: </span> </pre> <pre class="alt"><span class="lnum"> 39: </span> <span class="rem">//Chiudo l'applicazione</span></pre> <pre><span class="lnum"> 40: </span> application.Kill();</pre> <pre class="alt"><span class="lnum"> 41: </span> }</pre> <pre><span class="lnum"> 42: </span>}</pre> </div> <style type="text/css"><![CDATA[ .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }]]></style> <p>I commenti descrivono chiaramente la logica del metodo. Lanciamo il test (sempre con le mani dietro alla testa <img alt="smile_wink" src="http://spaces.live.com/rte/emoticons/smile_wink.gif" />) e godiamoci il risultato:</p> <p><a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/bmatte/WindowsLiveWriter/UIFunctionalTestingWithWhite_12787/CropperCapture%5B1%5D.png" target="_blank"><img title="CropperCapture[1]" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="196" alt="CropperCapture[1]" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/bmatte/WindowsLiveWriter/UIFunctionalTestingWithWhite_12787/CropperCapture%5B1%5D_thumb.png" width="862" border="0" /></a> </p> <p /> <p>Le prime tre righe sono “problemi” di <a href="http://www.codeplex.com/white/Wiki/View.aspx?title=Configuration&amp;referringTitle=Home" target="_blank">confgurazione</a> non essenziali per questa demo. </p> <p>Confrontando il solito metodo di test scritto con i due framework devo dire che <a href="http://www.codeplex.com/white" target="_blank">white</a> al momento offre un modello di pilotaggio della UI molto più ricco e semplice da utilizzare. Atro aspetto interessante è che <a href="http://www.codeplex.com/white" target="_blank">white</a> permette di testare anche applicazioni Java scritte in SWT!!</p> <p>Devo ammettere che vedere l’applicazione vivere di vita propria fa un certo effetto!!! <img alt="smile_teeth" src="http://spaces.live.com/rte/emoticons/smile_teeth.gif" /></p> <div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:79cbd1a6-410f-4088-86e4-0e83dd6c8349" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/WPF" rel="tag">WPF</a>,<a href="http://technorati.com/tags/Windows+Presentation+Foundation" rel="tag">Windows Presentation Foundation</a>,<a href="http://technorati.com/tags/FunctionalTest" rel="tag">FunctionalTest</a>,<a href="http://technorati.com/tags/White" rel="tag">White</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/94978.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/12/18/wpf-functional-testing-with-white.aspx Thu, 18 Dec 2008 23:23:02 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/12/18/wpf-functional-testing-with-white.aspx#feedback 2 http://blogs.ugidotnet.org/bmatte/comments/commentRss/94978.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/94978.aspx WPF UI Test Framework http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/wpf-ui-test-framework.aspx <p><a href="http://blogs.msdn.com/ivo_manolov/archive/2008/12/06/9181396.aspx" target="_blank">Ivo Manolov annumcia</a> sul proprio blog il <a href="http://www.codeplex.com/TestApi" target="_blank">rilascio di un tool open source</a> per automatizzare il test della UI sia essa in WPF pittosto che WinForm. Sempre sul suo blog potete leggere il <a href="http://blogs.msdn.com/ivo_manolov/archive/2008/12/15/9223397.aspx" target="_blank">primo post guida</a> del tool. Da questi post ho scoperto che esiste un <a href="http://blogs.msdn.com/wpftesting/" target="_blank">blog su MSDN dedicato al testing di WPF</a>. </p> <p>Esisteva già un tool open surce simile si chiama <a href="http://www.codeplex.com/white" target="_blank">white ed anche questo è hostato su CodePlex</a>.</p> <div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f3edd854-9fff-40ea-bb0c-b788235ffd4d" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/UnitTest" rel="tag">UnitTest</a>,<a href="http://technorati.com/tags/UI+Test" rel="tag">UI Test</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/94957.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/wpf-ui-test-framework.aspx Tue, 16 Dec 2008 17:02:24 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/wpf-ui-test-framework.aspx#feedback 3 http://blogs.ugidotnet.org/bmatte/comments/commentRss/94957.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/94957.aspx Google C++ Mocking Framework http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/google-c-mocking-framework.aspx <p>Ricordate il <a href="http://blogs.ugidotnet.org/bmatte/archive/2008/07/16/google-c-testing-framework.aspx" target="_blank">Google C++ Test Framework</a>? Bene! Adesso il Team di Google ha rilasciato anche un framework di <a href="http://googletesting.blogspot.com/2008/12/announcing-google-c-mocking-framework.html" target="_blank">Mocking per C++</a>. </p> <p>Vediamo se mi sarà utilie nella solita applicazione C++ che ho menzionato nel post passato.</p> <div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:5ffd4db2-4d85-4c2d-88f2-fdf326ecf930" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/Mocks" rel="tag">Mocks</a>,<a href="http://technorati.com/tags/UnitTest" rel="tag">UnitTest</a>,<a href="http://technorati.com/tags/TDD" rel="tag">TDD</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/94955.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/google-c-mocking-framework.aspx Tue, 16 Dec 2008 16:45:45 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/12/16/google-c-mocking-framework.aspx#feedback 1 http://blogs.ugidotnet.org/bmatte/comments/commentRss/94955.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/94955.aspx [Spring.NET #33] Spring.Aop, Advice http://blogs.ugidotnet.org/bmatte/archive/2008/05/10/spring.net-33-spring.aop-advice.aspx <p>Rappresenta la modalità di intercettamento di un motodo e quindi la modalità di intruduzione del codice. I tipi di Advice sono quattro:</p> <ul> <li><strong>AroundAdvice</strong>: implementa l'interfaccia <em>IMethodInterceptor</em> e permette il massimo controllo su un metodo dato che possiamo aggiungere logica primo e dopo l'invocazione del metodo target. Questo è  l'Advice più potente ma anche il più richioso, dato che possiamo dimenticare di chiamare il metodo <em>Proceed()</em> che rappresenta l'invocazione del metodo target. </li> <li><strong>BeforAdvice</strong>: implementa l'interfaccia <em>IBeforAdvice</em> e permette di introdurre codice soltanto prima dell'invocazione del metodo target. </li> <li><strong>AfterReturningAdvice</strong>: implementa l'interfaccia <em>IAfterReturningAdvice</em> e permette di introdurre codice soltanto dopo l'invocazione del metodo target. </li> <li><strong>ThrowAdvice</strong>: implementa l'interfaccia IThrowAdvice e permette di introdurre codice all'intercettazione di una eccezione. </li> </ul> <p>L'ordine di esecuzione degli Advice dello stesso tipo può essere controllata se quest'ultimi implementano l'interfaccia <em>IOrdered</em>. </p> <p>Gli Advice sono classificabili in due categorie: per classe e per istanza, differenti dal fatto che la seconda categoria dipende dallo stato interno della classe target mentre la prima no. Gli Advice elencati precedentemente fanno tutti parte della prima categoria. L'interfaccia <em>IAdvice</em>, invece, fa parte della seconda categoria e permette di creare dei mixin introducendo metodi e proprietà all'oggetto target. </p> <p>Procediamo con l'esempio incominciato nel precedente post. In questo episodio estrapoliamo il codice per la validazione dell'utente dalla classe <em>TransferService </em>e lo inseriamo una classe Advice, creando la classe <em>GenericPrincipalAroundAdvice. </em>Il risultato sarà il seguente:</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 111px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> TransferService : ITransferService</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Transfer(Account fromAccount, Account toAccount, <span style="color: #0000ff">int</span> amount)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> fromAccount.withdraw(amount);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> toAccount.deposit(amount);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> }</pre> </div> </div> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 117px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> GenericPrincipalAroundAdvice : IMethodInterceptor</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> _role = String.Empty;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Role</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> get { <span style="color: #0000ff">return</span> _role; }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> set { _role = <span style="color: #0000ff">value</span>; }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> Invoke(IMethodInvocation invocation)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span> IPrincipal _currentPrincipal = Thread.CurrentPrincipal;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> <span style="color: #0000ff">if</span> (!_currentPrincipal.IsInRole(_role))</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span> <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> SecurityException(<span style="color: #006080">"The logged user can't perform Transfer Account operation."</span>);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> <span style="color: #0000ff">object</span> returnValue = invocation.Proceed();</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span> <span style="color: #0000ff">return</span> returnValue;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 20:</span> }</pre> </div> </div> <p>Notiamo alla riga 16 l'infocazione del metodo intercettato (<em>Tansfer</em>) tramite il metodo <em>Proceed()</em>. In fine aggiorniamo la configurazione dell'Advisor impostando la proprietà Advice:</p> <pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">object</span> <span style="color: #ff0000">id</span>=<span style="color: #0000ff">"aroundAdvisor"</span> <span style="color: #ff0000">type</span>=<span style="color: #0000ff">"Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop"</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"Advice"</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">object</span> <span style="color: #ff0000">type</span>=<span style="color: #0000ff">"SpringSeries.Aop.Advice.GenericPrincipalAroundAdvice, 02.Advice"</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"Role"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"BankUser"</span> <span style="color: #0000ff">/&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">object</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">property</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"MappedName"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"Transfer"</span> <span style="color: #0000ff">/&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">object</span><span style="color: #0000ff">&gt;</span></pre> <p></p> <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a30a303e-71f7-4289-81b2-e399996bf4c6" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/Spring.NET" rel="tag">Spring.NET</a>,<a href="http://technorati.com/tags/AOP" rel="tag">AOP</a>,<a href="http://technorati.com/tags/Aspect%20Oriented%20Programming" rel="tag">Aspect Oriented Programming</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/92600.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/05/10/spring.net-33-spring.aop-advice.aspx Sat, 10 May 2008 11:42:50 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/05/10/spring.net-33-spring.aop-advice.aspx#feedback 1 http://blogs.ugidotnet.org/bmatte/comments/commentRss/92600.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/92600.aspx [Spring.NET #32] Spring.Aop, Pointcut e Advisor http://blogs.ugidotnet.org/bmatte/archive/2008/05/07/spring.net-32-spring.aop-pointcut-e-advisor.aspx <p>Un Pointcut definisce una regola di individuazione di un Joinpoint. Spring.NET offre diverse implementazioni di Pointcut, forniti come moduli indipendendi, implementati come singole entità in modo da renderli riutilizzabili ed intersecabili per diversi Advice. </p> <p>Ogni Pointcut implementa l'interfaccia <em>IPointcut</em>, la quale tramite i due membri <em>ITypeFilter</em> e <em>IMethodMatcher</em> permette di filtrare in base al tipo ed alla firma del metodo. Nella maggior parte dei casi le implementazioni dei Pointcut sono gestite in maniera statica (<em>StaticPointcut</em>), in modo da effettuare il caching del risultato di una valutazione di matching (operazione costosa in termini di performance) la prima volta che viene eseguita, questo permette di velocizzare la procedura di Weaving. Esiste un tipo di Pointcut non "cachabile", il <em>DynamicPointcut</em>, il quale effettua la valutazione di matching non solo in base al tipo ed alla firma del metodo, ma anche in base ai parametri passati al metodo stesso, quindi la valutazione avverrà ad ogni invocazione. Possiamo effettuare una operazione di unione dei Pointcut (verrà eseguito ogni Pointcut per il quale la valutazione di matching risulta vera), oppure una operazione di intersezione (verrà eseguito ogni Pointcut solo se la valutazione di matching risulta vera per tutti). </p> <p>Spring.NET fornisce built-in i seguenti Pointcut:</p> <ul> <li><strong>Regular Expression</strong>: è un generico Regular Expression Pointcut, il quale permette di definire una lista di pattern da applicare per il matching. Perchè la valutazione del Pointcut sia vera devono "matchare" tutti i pattern. Questo Pointcut è di tipo statico. </li> <li><strong>Attribute</strong>: permette di effettuare il matching di un metodo marcato con un determinato Attribute. Anche questo Pointcut è di tipo statico. </li> <li><strong>Control Flow</strong>: permette di effettuare il matching di un metodo in base al suo <em>StackTrace</em>. Per esempio possiamo indicare di applicare un Advice ad un metodo A solo se esso è stato chiamato da B. Questo Pointcut è di tipo dinamico, quindi molto costoso, in termini di performance. In più questo Pointcut richiede un po di attenzione perchè può incontrare dei problemi che la funzionalità di <em>Method Inlining</em> del Jit Compiler applicato quando generiamo un assembly in Release mode. Per evitare problemi ci sono una serie di tecniche mostrate qui: <a href="http://www.springframework.net/doc-latest/reference/html/aop.html#aop-dynamic-pointucts" target="_blank">Dynamic Pointcuts</a> </li> </ul> <p>Per implementare un nostro Pointcut baterà creare una classe che implementa l'interfaccia <em>IPointcut</em> oppure ereditare dalla classe base <em>StaticMethodMatcherPointcut</em>, la quale ci permette di risparmiare un po di codice di plumbing. </p> <p>L'unione di Pointcut e Advice si chiama Advisor, il quale crea di fatto un Aspetto modularizzato e riutilizzabile nella nostra applicazione. Dato che nel file di cofigurazione dobbiamo sempre indicare un Pointcut più una serie di Advice, Spring.NET fornisce una classe Advisor per ogni classe Pointcut (es: <em>RegularExpressionMethodPointcutAdvisor, AttributeMatchMethodPointcutAdvisor</em>) più una classe <em>DefaultPointcutAdvisor</em> in modo da semplificare la configurazione. </p> <p>Passiamo ad un esempio pratico, supponiamo di avere nel Service Layer una classe <em>TransferService</em> definita così:</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 131px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> TransferService : ITransferService</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> _role = String.Empty;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Role</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> set { _role = <span style="color: #0000ff">value</span>; }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Transfer(Account fromAccount, Account toAccount, <span style="color: #0000ff">int</span> amount)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> IPrincipal _currentPrincipal = Thread.CurrentPrincipal;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span> <span style="color: #0000ff">if</span> (!_currentPrincipal.IsInRole(_role))</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> SecurityException(<span style="color: #006080">"The logged user can't perform Transfer Account operation."</span>);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> fromAccount.withdraw(amount);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> toAccount.deposit(amount);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span> }</pre> </div> </div> <p>il nostro obbiettivo è di eliminare il codice di validazione dell'utente da questa classe per inserirlo in un aspetto. In questo post impostiamo solo l'Advisor che intercetterà l'invocazione del metodo, quindi nel file di configurazione inseriamo un <em>NameMatchMethodPointcutAdvisor</em>:</p> <pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">object</span> <span style="color: #ff0000">id</span>=<span style="color: #0000ff">"aroundAdvisor"</span> <span style="color: #ff0000">type</span>=<span style="color: #0000ff">"Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop"</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"Advice"</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">property</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"MappedName"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"Transfer"</span> <span style="color: #0000ff">/&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">object</span><span style="color: #0000ff">&gt;</span></pre> <p>Il <em>NameMatchMethodPointcutAdvisor</em> è una versione semplificata del <em>RegularExpressionMethodPointcutAdvisor, </em>il quale permette di definire un pattern di matching del metodo, che in questo caso è <em>"Transfer".</em></p> <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:cbac5731-f3dc-4551-9f00-02c75ec277cc" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/Spring.NET" rel="tag">Spring.NET</a>,<a href="http://technorati.com/tags/AOP" rel="tag">AOP</a>,<a href="http://technorati.com/tags/Aspect%20Oriented%20Programming" rel="tag">Aspect Oriented Programming</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/92560.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/05/07/spring.net-32-spring.aop-pointcut-e-advisor.aspx Wed, 07 May 2008 20:25:38 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/05/07/spring.net-32-spring.aop-pointcut-e-advisor.aspx#feedback 1 http://blogs.ugidotnet.org/bmatte/comments/commentRss/92560.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/92560.aspx [Spring.NET #31] Spring.Aop, Aspect Oriented Programming Framework Overview http://blogs.ugidotnet.org/bmatte/archive/2008/04/16/spring.net-31-spring.aop-aspect-oriented-programming-framework-overview.aspx <p>Altra parte fondamentale di Spring.NET è l' AOP Framework. Questo post non vuole spiegare che cosa è o non è l'AOP, ma vuole focalizzarsi soltanto su gli strumenti forniti da Spring.NET per utilizzare questo paradigma di programmazione nelle nostre applicazioni .NET. Tutta via, un minimo di infarinatura è obbligatoria, in poche pareloe l'Aspect Oriented Programming è un paradigma complementare all'Object Oriend Programming e permette di modularizzare gli aspetti ed i comportamenti trasversali della nostra applicazione, separandoli dal dominio applicativo. L' AOP è composta da i senguenti concetti non legati al framework utilizzato ma al paradigma stesso:</p> <ul> <li><strong>Aspect</strong>: rappresenta il comportamento trasversale, crosscutting concern ( esempio: Caching, Logging, Transaction Management) . </li> <li><strong>Joinpoint</strong>: rappresenta un punto ben preciso durante l'esecuzione del programma, come l'invocazione di un metodo. </li> <li><strong>Advice</strong>: rappresenta l'operazione che effetturà il motore di AOP per ogni Joinpoint. Esistono diversi tipi di Advice: Before, AfterReturning, Around e Throw, i quali permettono rispettivamente di effettuare operazioni in diversi istanti rispetto al Joinpoint interessato. </li> <li><strong>Pointcut</strong>: è l'insieme di regole che definisce quale Advice eseguire per quale Joinpoint. </li> <li><strong>Target</strong>: la classe che soddisfa uno o più Joinpoint e che sarà sottoposta ad un Advice, essa viene anche chiamata Advised o Proxied Object. </li> <li><strong>Introduction</strong>: permette la creazione di mixin aggiungendo metodi e/o proprità ad un Advised Object. </li> <li><strong>Proxy</strong>: un proxy creato in maniera dimanica generando codice IL a runtime. Questo proxy sarà il risultato dell'assemblaggio fra gli Advice e l'oggetto Target. </li> <li><strong>Weaving</strong>: rappresenta l'operazione di assemblamento degli Aspect per un determinato Target generando l' Advised Object. Questa operazione può essere fatta sia a compile time, sia a run time. Spring.NET adotta quest' ultima motodologia. </li> </ul> <p>Nei prossimo post descriverò le classi fornite da Spring.NET per la gestione di Pointcut, Advice, Aspects e Proxy.</p> <p>Come per gli altri componenti di Spring.NET il modulo di AOP e quello di IoC non sono dipendenti fra loro, ma complementari, quindi possiamo usare il primo piuttosto che il secondo, però se usati insieme daranno il massimo della potenzialità.</p> <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c59d4861-46e9-459b-9739-ca01c568da01" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/Spring.NET" rel="tag">Spring.NET</a>,<a href="http://technorati.com/tags/AOP" rel="tag">AOP</a>,<a href="http://technorati.com/tags/Aspect%20Oriented%20Programming" rel="tag">Aspect Oriented Programming</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/92230.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/04/16/spring.net-31-spring.aop-aspect-oriented-programming-framework-overview.aspx Wed, 16 Apr 2008 09:03:35 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/04/16/spring.net-31-spring.aop-aspect-oriented-programming-framework-overview.aspx#feedback http://blogs.ugidotnet.org/bmatte/comments/commentRss/92230.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/92230.aspx Evolutionary Databases - Design and Deployment http://blogs.ugidotnet.org/bmatte/archive/2008/03/26/evolutionary-databases---design-and-deployment.aspx <p>Esistono diversi tools di Refactoring, in continua evoluzione, che aiutano uno sviluppatore agile ad evolvere in maniera incrementale il proprio codice. Lo stesso non si può dire per quanto riguarda il refactoring del database, si perchè anche quest'ultimo vuole la sua parte, quindi anche il design della del database deve evolvere in maniera incrementale, user story dopo user story. A questo punto nasce il probleblema di gestire questa naturale evoluzione all'interno del processo di sviluppo software.</p> <p>L'approccio generalmente usato è quello di partire da uno script di base di crazione del database, da lì in poi per ogni user story che andrà a "toccare" il database verrà generato un script di aggiornamento che contiene le modifiche dalla versione precedente ed eventauli migrazione dati. Allo stesso modo lo script deve essere in grado di far "regredire" la struttura del database alla una release precedente. Tutti gli script seguenti a quello base saranno numerati, naturalmente in ordine crescente. Nel processo di build del progetto ci sarà un task che si occuperà di verificare la versione corrente del database e di eseguirein ordine tutti gli script necessari ad allineare il database alla nuova versione. </p> <p>Esistono diversi tools in rete sia per il mondo .NET che per altri come Java e Ruby. Tutti si basano sulla filosofia che ho descritto prima, però hanno forme diverse di implementazione. Esiste una categoria di tools che utilizza gli script SQL, un'altra che utilizza file XML ed un'ultima categoria che utilizza file di codice (C#,VB.NET,ecc). Di seguito un elenco (sicuramente non completo) dei tools, basati su script SQL: </p> <p>- dbdeploy.NET - <a href="http://sourceforge.net/projects/dbdeploy-net/">http://sourceforge.net/projects/dbdeploy-net/</a> <br /> - dbdeploy - <a href="http://dbdeploy.com">http://dbdeploy.com</a></p> <p>basati su XML: </p> <p>- MIGRATEdb - <a href="http://migratedb.sourceforge.net/">http://migratedb.sourceforge.net/</a> <br /> - LiquiBase - <a href="http://www.liquibase.org/">http://www.liquibase.org/</a></p> <p>basati su codice: </p> <p>- ActiveRecordMigration  - <a href="http://wiki.rubyonrails.com/rails/pages/UnderstandingMigrations">http://wiki.rubyonrails.com/rails/pages/UnderstandingMigrations</a> <br /> - SubSonic Migrate - <a href="http://blog.wekeroad.com/2007/10/03/subsonic-migrate-me/">http://blog.wekeroad.com/2007/10/03/subsonic-migrate-me/</a> <br /> - RikMigrations - <a href="http://www.codeplex.com/RikMigrations">http://www.codeplex.com/RikMigrations</a> <br /> - Migrator.NET - <a href="http://code.google.com/p/migratordotnet/">http://code.google.com/p/migratordotnet/</a></p> <p>Tutti questi tools si assomigliano molto, quello che secondo me può determinare la scelta di uno piuttosto che di un'altro è lo skill di chi dovrà creare l'update del database. Sicuramente se a modificare il database sarà un DBA, il quale ha una profonda conoscenza di SQL, il tool migliore sarà uno di quelli basati su script. Diversamente se sarà uno sviluppatore il tool più adatto sarà uno quelli basati su codice. Resta infine la categoria dei tools basati su file XML, a mio modesto parere, un ibrido senza nessun vantaggio, dato che richiede di racchiudere script SQL all'interno di appositi tag XML, complicandone la leggibilità. </p> <p>Io personalmente ho iniziato ad usare dbdeploy.NET, consigliatomi da <a href="http://blogs.ugidotnet.org/ABS/Default.aspx">Marco Abis</a>, che ringrazio. In fine segnalo questo <a href="http://trgoodwin.blogspot.com/2008/01/using-dbdeploynet.html" target="_blank">post-guida</a> all'uso di dbdeploy.NET e questo white paper <a href="http://dbdeploy.com/documentation/taking-control-of-your-database-development-white-paper/" target="_blank">Taking Control of your Database Development</a>,utile a prescindere dal tool usato.</p> <div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:083152f7-fcc2-4e7a-b20f-990bb6c09501" style="margin: 0px; padding: 0px; display: inline;">Technorati Tag: <a href="http://technorati.com/tags/Refactoring" rel="tag">Refactoring</a>,<a href="http://technorati.com/tags/Agile" rel="tag">Agile</a>,<a href="http://technorati.com/tags/Database" rel="tag">Database</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/91872.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/03/26/evolutionary-databases---design-and-deployment.aspx Wed, 26 Mar 2008 14:09:00 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/03/26/evolutionary-databases---design-and-deployment.aspx#feedback 5 http://blogs.ugidotnet.org/bmatte/comments/commentRss/91872.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/91872.aspx [Spring.NET #30] Spring.Core, Definire oggetti tramite ObjectDefinitionBuilder fluent interface http://blogs.ugidotnet.org/bmatte/archive/2008/03/12/spring.net-30-spring.core-definire-oggetti-tramite-objectdefinitionbuilder-fluent-interface.aspx <p>Spring.NET grazie alla classe <em>ObjectDefinitionBuilder </em>espone delle <em>flunt interface</em> API che permettono di definire oggetti da registrare nell' <em>ApplicationContext</em>. Per mostrare questa funzionalità non documentata replicherò l'esempio mostrato nel post <a href="http://blogs.ugidotnet.org/bmatte/archive/2007/10/03/spring.net-14-spring.core-ioc-e-di-setter-injection.aspx" target="_blank">[Spring.NET #14] Spring.Core, IoC e DI (Setter Injection)</a> :</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 231px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">using</span> System;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> <span style="color: #0000ff">using</span> Spring.Context.Support;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">using</span> Spring.Objects.Factory.Support;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> <span style="color: #0000ff">namespace</span> SpringSeries.Core.ObjectDefinitionBuilderFluentInterface</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> <span style="color: #0000ff">class</span> Program</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> GenericApplicationContext _ctx = <span style="color: #0000ff">new</span> GenericApplicationContext();</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> _ctx.RegisterObjectDefinition(<span style="color: #006080">"EngTranslator"</span>, ObjectDefinitionBuilder</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span> .RootObjectDefinition(<span style="color: #0000ff">new</span> DefaultObjectDefinitionFactory(), <span style="color: #0000ff">typeof</span>(EnglishToItalianTranslator))</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> .SetSingleton(<span style="color: #0000ff">true</span>)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> .ObjectDefinition);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span> _ctx.RegisterObjectDefinition(<span style="color: #006080">"SpaTranslator"</span>, ObjectDefinitionBuilder</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> .RootObjectDefinition(<span style="color: #0000ff">new</span> DefaultObjectDefinitionFactory(), <span style="color: #0000ff">typeof</span>(SpanishToItalianTranslator))</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 20:</span> .SetSingleton(<span style="color: #0000ff">true</span>)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 21:</span> .ObjectDefinition);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 22:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 23:</span> _ctx.RegisterObjectDefinition(<span style="color: #006080">"ConsoleLog"</span>, ObjectDefinitionBuilder</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 24:</span> .RootObjectDefinition(<span style="color: #0000ff">new</span> DefaultObjectDefinitionFactory(), <span style="color: #0000ff">typeof</span>(ConsoleTranslatorLog))</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 25:</span> .SetSingleton(<span style="color: #0000ff">true</span>)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 26:</span> .ObjectDefinition);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 27:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 28:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 29:</span> _ctx.RegisterObjectDefinition(<span style="color: #006080">"Translator"</span>, ObjectDefinitionBuilder</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 30:</span> .RootObjectDefinition(<span style="color: #0000ff">new</span> DefaultObjectDefinitionFactory(), <span style="color: #0000ff">typeof</span>(PhraseTranslator))</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 31:</span> .AddConstructorArgReference(<span style="color: #006080">"EngTranslator"</span>)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 32:</span> .AddPropertyReference(<span style="color: #006080">"Log"</span>,<span style="color: #006080">"ConsoleLog"</span>)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 33:</span> .SetSingleton(<span style="color: #0000ff">true</span>)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 34:</span> .ObjectDefinition);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 35:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 36:</span> PhraseTranslator _translator = (PhraseTranslator)_ctx.GetObject(<span style="color: #006080">"Translator"</span>);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 37:</span> Console.WriteLine(_translator.Translate(<span style="color: #006080">"Hello Spring.NET !!"</span>));</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 38:</span> Console.WriteLine(_translator.Translate(<span style="color: #006080">"Hola Spring.NET !!"</span>));</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 39:</span> Console.Read();</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 40:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 41:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 42:</span> }</pre> </div> </div> <p>L'esempio è abbastanza autoesplicativo, come prima cosa creo un <em>ApllicationContext</em> vuoto grazie alla classe <em>GenericApplicationContext</em>, in seguito registro la definizione degli oggetti tramite il metodo <em>RegisterObjectDefinition</em>, il quale accetta due parametri, l'identificativo di tipo stringa ed un'istanza di <em>IObjectDefinition. </em>Per ottenere le varie istanze di <em>IObjectDefinition</em> utilizziamo la classe <em>ObjectDefinitionBuilder</em>.</p> <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6b57b268-bdb1-4441-9082-20efe510b0c7" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/Spring.NET" rel="tag">Spring.NET</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/91651.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/03/12/spring.net-30-spring.core-definire-oggetti-tramite-objectdefinitionbuilder-fluent-interface.aspx Wed, 12 Mar 2008 01:51:55 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/03/12/spring.net-30-spring.core-definire-oggetti-tramite-objectdefinitionbuilder-fluent-interface.aspx#feedback http://blogs.ugidotnet.org/bmatte/comments/commentRss/91651.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/91651.aspx [Spring.NET #29] Spring.Core, Loosely Coupled Event Wiring http://blogs.ugidotnet.org/bmatte/archive/2008/03/09/spring.net-29-spring.core-loosely-coupled-event-wiring.aspx <p>Grazie al motore di IoC, Spring.NET offre la funzionalità di <em><strong>Loosely Coupled Event Wiring,</strong></em> vale a dire la possibilità di scatenare ed intercettare eventi senza un legame diretto fra il <strong>publisher</strong> ed il <strong>subscriber</strong>. Il meccanismo avviene grazie ad un Registry mantenuto da Spring.NET, dentro al quale il publisher registra i propri aventi, rendendoli pubblici, a questo punto il subscriber potrà "dire" a Spring.NET quale eventi sottoscrivere. Passiamo subito ad un esempio pratico, creiamo una ConsoleApplication ed aggiungiamo la reference a <em>Spring.Core.dll.</em> Procediamo con l'oggetto <strong>publisher</strong>, come prima cosa aggiungiamo una classe <em>CustomEventArgs</em>, la quale sarà utilizzata nell'evento scatenato dalla classe <em>EventPublisher:</em></p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 126px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">using</span> System;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">namespace</span> SpringSeries.Core.EventWiring</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> CustomEventArgs : EventArgs</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> _eventMessage;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> <span style="color: #0000ff">public</span> CustomEventArgs(<span style="color: #0000ff">string</span> eventMessage)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> _eventMessage = eventMessage;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> EventMessage</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> get { <span style="color: #0000ff">return</span> _eventMessage; }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> }</pre> </div> </div> <p>dopo creiamo la classe <em>EventPublisher, </em>la quale espone l'evento <em>SimpleEvent:</em></p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 127px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">using</span> System;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">namespace</span> SpringSeries.Core.EventWiring</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">delegate</span> <span style="color: #0000ff">void</span> SimpleEvent(<span style="color: #0000ff">object</span> sender, CustomEventArgs args);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> EventPublisher</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> _publisherName;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">event</span> SimpleEvent _simpleEvent;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> <span style="color: #0000ff">public</span> EventPublisher()</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> PublisherName</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> get { <span style="color: #0000ff">return</span> _publisherName; }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 20:</span> set { _publisherName = <span style="color: #0000ff">value</span>; }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 21:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 22:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 23:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> RaiseSimpleEvent()</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 24:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 25:</span> <span style="color: #0000ff">if</span> (_simpleEvent != <span style="color: #0000ff">null</span>)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 26:</span> _simpleEvent(<span style="color: #0000ff">this</span>, <span style="color: #0000ff">new</span> CustomEventArgs(<span style="color: #006080">"SimpleEvent raised from "</span> + _publisherName));</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 27:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 28:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 29:</span> }</pre> </div> </div> <p>Fatto il <strong>publisher</strong> passiamo alla creazione della classe che farà da <strong>subscriber</strong>, <em>EventSubscriber. </em>Questa classe deve avere un metodo con la stessa firma dell'evento che vuote intercettare:</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 129px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">using</span> System;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">namespace</span> SpringSeries.Core.EventWiring</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> EventSubscriber</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> _eventHandled = <span style="color: #0000ff">false</span>;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> <span style="color: #0000ff">public</span> EventSubscriber()</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> HandleSimpleEvent(<span style="color: #0000ff">object</span> sender, CustomEventArgs args)</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> Console.WriteLine(<span style="color: #006080">"Handled SimpleEvent event with args: "</span> + args.EventMessage);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> _eventHandled = <span style="color: #0000ff">true</span>;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> EventHandled</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 20:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 21:</span> get { <span style="color: #0000ff">return</span> _eventHandled; }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 22:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 23:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 24:</span> }</pre> </div> </div> <p>Configuriamo il <strong>publisher</strong> ed il <strong>subscriber</strong> all'interno del file di configurazione:</p> <pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">objects</span> <span style="color: #ff0000">xmlns</span>=<span style="color: #0000ff">"http://www.springframework.net"</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">object</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"MyEventPublisher"</span> <span style="color: #ff0000">type</span>=<span style="color: #0000ff">"SpringSeries.Core.EventWiring.EventPublisher, 21.EventWiring"</span> <span style="color: #ff0000">singleton</span>=<span style="color: #0000ff">"false"</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"PublisherName"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"Matteo event publisher"</span> <span style="color: #0000ff">/&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">object</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">object</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"MyEventSubscriber"</span> <span style="color: #ff0000">type</span>=<span style="color: #0000ff">"SpringSeries.Core.EventWiring.EventSubscriber, 21.EventWiring"</span> <span style="color: #ff0000">singleton</span>=<span style="color: #0000ff">"false"</span> <span style="color: #0000ff">/&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">objects</span><span style="color: #0000ff">&gt;</span></pre> <p>Nel corpo del metodo <em>Main</em> registriamo l'evento <em>SimpleEvent</em> della classe <em>EventPublisher</em> in maniera programmatica, grazie al metodo <em>PublishEvents </em>dell' <em>ApplicationContext.</em> Creaiamo due istanze di <em>EventSubscriber</em> e registriamo solo la prima come <strong>subscriber</strong>. La sottoscrizione avviene grazie al metodo <em>Subscribe</em> dell' <em>ApplicationContext. </em></p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 133px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">using</span> System;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> <span style="color: #0000ff">using</span> Spring.Context;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff">using</span> Spring.Context.Support;</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> <span style="color: #0000ff">namespace</span> SpringSeries.Core.EventWiring</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">sealed</span> <span style="color: #0000ff">class</span> Program</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> [STAThread]</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main()</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 11:</span> {</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 12:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 13:</span> IApplicationContext _ctx = ContextRegistry.GetContext();</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 14:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 15:</span> EventPublisher _publisher = (EventPublisher)_ctx.GetObject(<span style="color: #006080">"MyEventPublisher"</span>);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 16:</span> <span style="color: #008000">// registro nel context gli eventi dell'oggetto EventPublisher</span></pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 17:</span> _ctx.PublishEvents(_publisher);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 18:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 19:</span> EventSubscriber _subscriber1 = (EventSubscriber)_ctx.GetObject(<span style="color: #006080">"MyEventSubscriber"</span>);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 20:</span> EventSubscriber _subscriber2 = (EventSubscriber)_ctx.GetObject(<span style="color: #006080">"MyEventSubscriber"</span>);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 21:</span> <span style="color: #008000">// registro nel context che il subscriber1 sottoscrive gli eventi dell'oggetto EventPublisher</span></pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 22:</span> _ctx.Subscribe(_subscriber1, <span style="color: #0000ff">typeof</span>(EventPublisher));</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 23:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 24:</span> Console.WriteLine(<span style="color: #006080">"Publisher name: "</span> + _publisher.PublisherName);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 25:</span> </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 26:</span> Console.WriteLine(<span style="color: #006080">"Subscriber 1 Event Handled: "</span> + _subscriber1.EventHandled);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 27:</span> Console.WriteLine(<span style="color: #006080">"Subscriber 2 Event Handled: "</span> + _subscriber2.EventHandled);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 28:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 29:</span> <span style="color: #008000">// raises a publisher event...</span></pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 30:</span> _publisher.RaiseSimpleEvent();</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 31:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 32:</span> Console.WriteLine(<span style="color: #006080">"Subscriber 1 Event Handled: "</span> + _subscriber1.EventHandled);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 33:</span> Console.WriteLine(<span style="color: #006080">"Subscriber 2 Event Handled: "</span> + _subscriber2.EventHandled);</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 34:</span>  </pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 35:</span> Console.Read();</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 36:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 37:</span> }</pre> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 38:</span> }</pre> </div> </div> <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:29860ae6-a337-4b2e-9400-23602459b826" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tag: <a href="http://technorati.com/tags/Spring.NET" rel="tag">Spring.NET</a></div><img src="http://blogs.ugidotnet.org/bmatte/aggbug/91591.aspx" width="1" height="1" /> Matteo Baglini http://blogs.ugidotnet.org/bmatte/archive/2008/03/09/spring.net-29-spring.core-loosely-coupled-event-wiring.aspx Sun, 09 Mar 2008 13:40:33 GMT http://blogs.ugidotnet.org/bmatte/archive/2008/03/09/spring.net-29-spring.core-loosely-coupled-event-wiring.aspx#feedback 1 http://blogs.ugidotnet.org/bmatte/comments/commentRss/91591.aspx http://blogs.ugidotnet.org/bmatte/services/trackbacks/91591.aspx