<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Marco Amendola</title>
	<atom:link href="http://marcoamendola.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://marcoamendola.wordpress.com</link>
	<description>.Net thoughs</description>
	<lastBuildDate>Thu, 26 May 2011 01:48:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='marcoamendola.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Marco Amendola</title>
		<link>http://marcoamendola.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://marcoamendola.wordpress.com/osd.xml" title="Marco Amendola" />
	<atom:link rel='hub' href='http://marcoamendola.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Model-first navigation in WP7 with Caliburn.Micro</title>
		<link>http://marcoamendola.wordpress.com/2011/05/26/model-first-navigation-in-wp7-with-caliburn-micro/</link>
		<comments>http://marcoamendola.wordpress.com/2011/05/26/model-first-navigation-in-wp7-with-caliburn-micro/#comments</comments>
		<pubDate>Thu, 26 May 2011 01:03:40 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Caliburn.Micro]]></category>
		<category><![CDATA[model-first]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/?p=125</guid>
		<description><![CDATA[I just saw Rob’s recent UriBuilder addition in Caliburn.Micro source; it really simplifies the configuration of the View Model of the page to open through the use of a fluent-style API: navigationService.UriFor&#60;PageTwoViewModel&#62;() .WithParam(x =&#62; x.NumberOfTabs, 5) .Navigate(); Also, it brings WP7 navigation stuff (which is strongly page oriented) a step closer to a model-first approach. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=125&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just saw <a href="http://caliburnmicro.codeplex.com/SourceControl/changeset/changes/3bd66d203cc4">Rob’s recent UriBuilder addition</a> in <a href="http://caliburnmicro.codeplex.com">Caliburn.Micro</a> source; it really simplifies the configuration of the View Model of the page to open through the use of a fluent-style API:</p>
<pre class="brush: csharp;">
navigationService.UriFor&lt;PageTwoViewModel&gt;()
 .WithParam(x =&gt; x.NumberOfTabs, 5)
 .Navigate();
</pre>
<p>Also, it brings WP7 navigation stuff (which is strongly page oriented) a step closer to a model-first approach.</p>
<p>I was recently struggling with an attempt to improve this very area.</p>
<p>My goal, however, was to navigate to a <strong>real </strong>View Model instance, with the aim to get <strong>exactly</strong> that instance bound to the new page.</p>
<p>The idea I had is very simple (apparently, even <em>too </em>simple, which makes me think that it could eventually have some problems on the long run):</p>
<ul>
<li>in the calling VM, create and set up an instance of the destination VM;</li>
<li>put the VM instance into a slot of the Phone Service state;</li>
<li>navigate to a generic &#8220;hosting&#8221; page (HostPage);</li>
<li>HostPage has a corresponding HostPageViewModel based on Conductor&lt;&gt; class; CM already takes care of binding it to the new page when the navigation is completed.On initialization, the HostPageViewModel just activates whatever it finds in the Phone Service state slot used before;</li>
<li>the View corresponding to the destination ViewModel is resolved and composed as usual inside the HostPage.</li>
</ul>
<p>Actually, this is very similar to the old-school-web-application trick of using the http session to <a href="http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx#sectionToggle2">pass objects between different pages</a>.</p>
<p>Not very elegant, yet effective.</p>
<p>I built a simple proof of concept showing the idea and the trick seems to work (I wonder why I didn’t try it before…).</p>
<p>Here the key points:</p>
<pre class="brush: csharp;">
//the hosting VM
public class HostPageViewModel : Conductor&lt;object&gt;
{
	public const string TARGET_VM_KEY = &quot;cm-navigation-target-vm&quot;;

	IPhoneService phoneService;
	public HostPageViewModel(IPhoneService phoneService) {
		this.phoneService = phoneService;
	}

	protected override void OnInitialize()
	{
		base.OnInitialize();
		if (!phoneService.State.ContainsKey(TARGET_VM_KEY)) return;

		var targetVM = phoneService.State[TARGET_VM_KEY];
		phoneService.State.Remove(TARGET_VM_KEY);

		this.ActivateItem(targetVM);
	}
}
</pre>
<pre class="brush: xml;">
&lt;!-- the hosting View --&gt;
&lt;phone:PhoneApplicationPage x:Class=&quot;Caliburn.Micro.HelloWP7.HostPage&quot; ...&gt;
    &lt;ContentControl Name=&quot;ActiveItem&quot;
        HorizontalContentAlignment=&quot;Stretch&quot;
        VerticalContentAlignment=&quot;Stretch&quot; /&gt;
&lt;/phone:PhoneApplicationPage&gt;
</pre>
<pre class="brush: csharp;">
//a convenience extension method
public static class NavigationExtension
{
	public static void NavigateTo(this INavigationService navigationService, object targetModel)
	{
		IoC.Get&lt;IPhoneService&gt;().State[HostPageViewModel.TARGET_VM_KEY] = targetModel;
		navigationService.UriFor&lt;HostPageViewModel&gt;().Navigate();
	}
}
</pre>
<pre class="brush: csharp;">
//the usage
PageTwoViewModel model = ... //obtain a new instance of the destination VM
model.NumberOfTabs = 5; //sets the VM up
navigationService.NavigateTo(model);
</pre>
<p>It has the great advantage of being <strong>very </strong>similar to the usual way we deal with dialogs in Caliburn.Micro.</p>
<p>Also, it allows to inject into the destination VM any data already available in the context of the calling VM, thus saving an hit to remote services or the use of a global data cache.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=125&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2011/05/26/model-first-navigation-in-wp7-with-caliburn-micro/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>
	</item>
		<item>
		<title>A quick Caliburn.Micro tip: WebService result</title>
		<link>http://marcoamendola.wordpress.com/2010/10/23/a-quick-caliburn-micro-tip-webservice-result/</link>
		<comments>http://marcoamendola.wordpress.com/2010/10/23/a-quick-caliburn-micro-tip-webservice-result/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 10:20:15 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Caliburn.Micro]]></category>
		<category><![CDATA[Caliburn]]></category>
		<category><![CDATA[Coroutine]]></category>
		<category><![CDATA[IResult]]></category>
		<category><![CDATA[Micro]]></category>
		<category><![CDATA[Wcf]]></category>
		<category><![CDATA[WebService]]></category>

		<guid isPermaLink="false">https://marcoamendola.wordpress.com/?p=105</guid>
		<description><![CDATA[UPDATE 2011/01/03 Fixed a couple bugs: Missing exception handling on callback execution Missing null check on Message property Many thanks to Luca D&#8217;Angelo for pointing them out. A user recently asked, on Caliburn.Micro forum, for an equivalent version of WebServiceResult, a convenience IResult built by Rob in the (full) Caliburn’s Contact Manager sample. Porting was quite [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=105&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em><strong>UPDATE 2011/01/03</strong></em></p>
<p><em>Fixed a couple bugs:</em><br />
<em></p>
<ul>
<li>Missing exception handling on callback execution</li>
<li>Missing null check on Message property</li>
</ul>
<p>Many thanks to <a href="http://www.linkedin.com/profile/view?id=95090197" target="_blank">Luca D&#8217;Angelo</a> for pointing them out.<br />
</em></p>
<p><em> </em><br />
<em> </em><br />
</p>
<p>A user <a href="http://caliburnmicro.codeplex.com/Thread/View.aspx?ThreadId=231970" target="_blank">recently asked</a>, on Caliburn.Micro forum, for an equivalent version of WebServiceResult, a convenience IResult built by <a href="http://devlicio.us/blogs/rob_eisenberg/" target="_blank">Rob</a> in the (full) Caliburn’s Contact Manager sample.</p>
<p>Porting was quite straightforward, despite the important difference in the framework internal structure.</p>
<p>Here is the class source:</p>
<pre class="brush: csharp;">
using System;
using System.Linq;
using System.Linq.Expressions;
public class WebServiceResult&lt;T, K&gt; : IResult
	where T : new()
	where K : EventArgs&lt;
{
	readonly static Func&lt;bool&gt; ALWAYS_FALSE_GUARD= () =&gt; false;
	readonly static Func&lt;bool&gt; ALWAYS_TRUE_GUARD = () =&gt; true;
	private readonly Action&lt;K&gt; _callback;
	private readonly Expression&lt;Action&lt;T&gt;&gt; _serviceCall;
	private ActionExecutionContext _currentContext;
	private Func&lt;bool&gt; _originalGuard;
	public WebServiceResult(Expression&lt;Action&lt;T&gt;&gt; serviceCall)
	{
		_serviceCall = serviceCall;
	}
	public WebServiceResult(Expression&lt;Action&lt;T&gt;&gt; serviceCall, Action&lt;K&gt; callback)
	{
		_serviceCall = serviceCall;
		_callback = callback;
	}
	public event EventHandler&lt;ResultCompletionEventArgs&gt; Completed = delegate { };
	public void Execute(ActionExecutionContext context)
	{
		_currentContext = context;
		//if you would to disable the control that caused the service to be called, you could do this:
		ChangeAvailability(false);
		var lambda = (LambdaExpression)_serviceCall;
		var methodCall = (MethodCallExpression)lambda.Body;
		var eventName = methodCall.Method.Name.Replace(&quot;Async&quot;, &quot;Completed&quot;);
		var eventInfo = typeof(T).GetEvent(eventName);
		var service = new T();
		eventInfo.AddEventHandler(service, new EventHandler&lt;K&gt;(OnEvent));
		_serviceCall.Compile()(service);
	}
	public void OnEvent(object sender, K args)
	{
		//re-enable the control that caused the service to be called:
		ChangeAvailability(true);
                try {
		    if (_callback != null)
			_callback(args);
	    	    Completed(this, new ResultCompletionEventArgs());
                } catch (Exception ex) {
	    	    Completed(this, new ResultCompletionEventArgs{ Error = ex });
                }
	}
	private void ChangeAvailability(bool isAvailable)
	{
		if (_currentContext == null || _currentContext.Message == null) return;
		if (!isAvailable) {
			_originalGuard = _currentContext.CanExecute;
			_currentContext.CanExecute = ALWAYS_FALSE_GUARD;
		}
		else if (_currentContext.CanExecute == ALWAYS_FALSE_GUARD) {
			_currentContext.CanExecute = _originalGuard ?? ALWAYS_TRUE_GUARD;
		}
		_currentContext.Message.UpdateAvailability();
	}
}
</pre>
<p>The invocation:</p>
<pre class="brush: csharp;">
//in the service code
public class MyService
{
	[OperationContract]
	public int DoWork(int value)
	{
		return new Random().Next();
	}
}
//in the calling ViewModel code
public IEnumerable&lt;IResult&gt; CallService()
{
	int theParameter = 0;
	yield return new WebServiceResult&lt;MyServiceClient, DoWorkCompletedEventArgs&gt;(
		x =&gt; x.DoWorkAsync(theParameter),
		x =&gt; UseResultElsewhere(x.Result)
	);
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=105&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2010/10/23/a-quick-caliburn-micro-tip-webservice-result/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>
	</item>
		<item>
		<title>A Caliburn.Micro recipe: filters</title>
		<link>http://marcoamendola.wordpress.com/2010/08/10/a-caliburn-micro-recipe-filters/</link>
		<comments>http://marcoamendola.wordpress.com/2010/08/10/a-caliburn-micro-recipe-filters/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 01:09:57 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Caliburn.Micro]]></category>
		<category><![CDATA[Caliburn]]></category>
		<category><![CDATA[Micro]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[IResult]]></category>
		<category><![CDATA[Coroutine]]></category>
		<category><![CDATA[Customization]]></category>

		<guid isPermaLink="false">https://marcoamendola.wordpress.com/2010/08/10/a-caliburn-micro-recipe-filters/</guid>
		<description><![CDATA[Caliburn.Micro is a lightweight implementation of most core Caliburn feaures in a small assembly. Rob did a great work keeping footprint small, but something was necessarily left over. One of the features missing in Caliburn.Micro is filters, a set of action decorations aimed to provide additional behaviors to a particular action. Filters bring two major [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=96&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://caliburnmicro.codeplex.com/" target="_blank">Caliburn.Micro</a> is a lightweight implementation of most core <a href="http://caliburn.codeplex.com/" target="_blank">Caliburn</a> feaures in a small assembly. <a href="http://devlicio.us/blogs/rob_eisenberg/" target="_blank">Rob</a> did a great work keeping footprint small, but something was necessarily left over.</p>
<p>One of the features missing in Caliburn.Micro is filters, a set of action decorations aimed to provide additional behaviors to a particular action. Filters bring two major advantages:</p>
<ul>
<li>they help to keep View Model free from noisy code not concerning its main purpose (thus simplifying its unit testing, too);</li>
<li>they allow to share the implementation of cross-cutting concerns between different View Models, moving it into infrastructure components.</li>
</ul>
<p>Since I use filters quite often, I wanted to provide an implementation for Caliburn.Micro, too.</p>
<p>I could have ported it from Caliburn just fixing some slightly changed signature; yet, in the spirit of keeping things small and simple, I decided to use a less fine-grained design. Plus, I wanted to proof a design idea going through my mind from a while.<br />
Basically, I noted a similarity in the hook point provided by Caliburn infrastructure to filters and IResults (coroutines), so I would check if the two concepts could be unified; this would have allowed to include filters in Caliburn.Micro with little additional infrastructure.</p>
<h2>Design</h2>
<p>Filters falls into two main categories, depending on the mechanism used to interact with the target action: IExecutionWrapper and IContextAware.</p>
<p>The common IFilter interface is little more than a marker and just defines a Priority property aimed to trim the filter application order:</p>
<pre class="brush: csharp;">
public interface IFilter {
	int Priority { get; }
}
</pre>
<h3>IExecutionWrapper</h3>
<p>Most filters capability are built around AOP concepts and works through the interception of an action execution: doing this allows to add operation before and after the action execution itself or something more complex like dispatching the action in another thread.<br />
Coroutine infrastructure already has this capability, so a filter willing to intercept an action can simply wrap the original execution into a “wrapping” IResult:</p>
<pre class="brush: csharp;">
public interface IExecutionWrapper : IFilter {
	IResult Wrap(IResult inner);
}
</pre>
<p>To enable filter hooking, I had to replace the core invocation method of ActionMessage:</p>
<pre class="brush: csharp;">
//in bootstrapper code:
ActionMessage.InvokeAction = FilterFrameworkCoreCustomization.InvokeAction;
...

public static class FilterFrameworkCoreCustomization
{
    ...
    public static void InvokeAction(ActionExecutionContext context)
    {
        var values = MessageBinder.DetermineParameters(context, context.Method.GetParameters());
        IResult result = new ExecuteActionResult(values);
        var wrappers = FilterManager.GetFiltersFor(context).OfType&lt;IExecutionWrapper&gt;();
        var pipeline = result.WrapWith(wrappers);

        //if pipeline has error, action execution should throw!
        pipeline.Completed += (o, e) =&gt;
        {
            Execute.OnUIThread(() =&gt;
            {
                if (e.Error != null) throw new Exception(
                    string.Format(&quot;An error occurred while executing {0}&quot;, context.Message),
                    e.Error
                );
            });
        };

        pipeline.Execute(context);
    }
    ...
}
</pre>
<p>Every action is actually executed within an ExecuteActionResult (code omitted here) that deals with simple action as well as coroutines, uniforming all of them to a common IResult interface.</p>
<p>This “core” IResult is afterwards wrapped over and over by each filter attached to the action and finally executed.</p>
<p>Let’s have a look at FilterManager:</p>
<pre class="brush: csharp;">
public static class FilterManager
{

    public static IResult WrapWith(this IResult inner, IEnumerable&lt;IExecutionWrapper&gt; wrappers)
    {
        IResult previous = inner;
        foreach (var wrapper in wrappers)
        {
            previous = wrapper.Wrap(previous);
        }
        return previous;
    }

    public static Func&lt;ActionExecutionContext, IEnumerable&lt;IFilter&gt;&gt; GetFiltersFor = (context) =&gt; {
        return context.Target.GetType().GetAttributes&lt;IFilter&gt;(true)
                .Union(context.Method.GetAttributes&lt;IFilter&gt;(true))
                .OrderBy(x =&gt; x.Priority);
    };
}
</pre>
<p>Note that the GetFiltersFor method is replaceable to allow for another filter lookup strategy (for example, based on convention or external configuration instead of attributes).</p>
<h3>IContextAware</h3>
<p>While IExecutionWrapper-s does their work during the action execution, the other filter category, IContextAware, operates when action is <span style="text-decoration:underline;">not</span> executing, providing preconditions for execution (the related predicate is held by ActionExecutionContext) or observing the ViewModel to force an update of the action availability:</p>
<pre>public interface IContextAware : IFilter, IDisposable
{
	void MakeAwareOf(ActionExecutionContext context);
}</pre>
<p>Filters implementing this interface are given a chance, during ActionMessage initialization, to hook the execution context; to achieve this, I had to slightly tweak the ActionMessage again:</p>
<pre class="brush: csharp;">
//in bootstrapper code:
var oldPrepareContext = ActionMessage.PrepareContext;
ActionMessage.PrepareContext = context =&gt;
{
    oldPrepareContext(context);
    FilterFrameworkCoreCustomization.PrepareContext(context);
};
...

public static class FilterFrameworkCoreCustomization
{
    ...
    public static void PrepareContext(ActionExecutionContext context)
    {
        var contextAwareFilters = FilterManager.GetFiltersFor(context).OfType&lt;IContextAware&gt;()
            .ToArray();
        contextAwareFilters.Apply(x =&gt; x.MakeAwareOf(context));

        context.Message.Detaching += (o, e) =&gt;
        {
            contextAwareFilters.Apply(x =&gt; x.Dispose());
        };
    }
    ...
}
</pre>
<h2>Implementing filters</h2>
<p>To simplify filters construction, I made a base class for IExecutionWrapper which includes all the boilerplate code and provides some standard  customization point:</p>
<pre class="brush: csharp;">
public abstract class ExecutionWrapperBase : Attribute, IExecutionWrapper, IResult
{
    public int Priority { get; set; }

    /// &lt;summary&gt;
    /// Check prerequisites
    /// &lt;/summary&gt;
    protected virtual bool CanExecute(ActionExecutionContext context) { return true;}
    /// &lt;summary&gt;
    /// Called just before execution (if prerequisites are met)
    /// &lt;/summary&gt;
    protected virtual void BeforeExecute(ActionExecutionContext context) { }
    /// &lt;summary&gt;
    /// Called after execution (if prerequisites are met)
    /// &lt;/summary&gt;
    protected virtual void AfterExecute(ActionExecutionContext context) { }
    /// &lt;summary&gt;
    /// Allows to customize the dispatch of the execution
    /// &lt;/summary&gt;
    protected virtual void Execute(IResult inner, ActionExecutionContext context)
    {
        inner.Execute(context);
    }
    /// &lt;summary&gt;
    /// Called when an exception was thrown during the action execution
    /// &lt;/summary&gt;
    protected virtual bool HandleException(ActionExecutionContext context, Exception ex) { return false; }

    IResult _inner;
    IResult IExecutionWrapper.Wrap(IResult inner)
    {
        _inner = inner;
        return this;
    }

    void IResult.Execute(ActionExecutionContext context)
    {
        if (!CanExecute(context))
        {
            _completedEvent.Invoke(this, new ResultCompletionEventArgs { WasCancelled = true });
            return;
        }

        try
        {

            EventHandler&lt;ResultCompletionEventArgs&gt; onCompletion = null;
            onCompletion = (o, e) =&gt;
            {
                _inner.Completed -= onCompletion;
                AfterExecute(context);
                FinalizeExecution(context, e.WasCancelled, e.Error);
            };
            _inner.Completed += onCompletion;

            BeforeExecute(context);
            Execute(_inner, context);

        }
        catch (Exception ex)
        {
            FinalizeExecution(context, false, ex);
        }
    }

    void FinalizeExecution(ActionExecutionContext context, bool wasCancelled, Exception ex)
    {
        if (ex != null &amp;&amp; HandleException(context, ex))
            ex = null;

        _completedEvent.Invoke(this, new ResultCompletionEventArgs { WasCancelled = wasCancelled, Error = ex });
    }

    event EventHandler&lt;ResultCompletionEventArgs&gt; _completedEvent = delegate { };
    event EventHandler&lt;ResultCompletionEventArgs&gt; IResult.Completed
    {
        add { _completedEvent += value; }
        remove { _completedEvent -= value; }
    }
}
</pre>
<p>Finally I could reproduce the behavior of some well known Caliburn filters in Caliburn.Micro:</p>
<pre class="brush: csharp;">
/// &lt;summary&gt;
/// Provides asynchronous execution of the action in a background thread
/// &lt;/summary&gt;
public class AsyncAttribute : ExecutionWrapperBase
{
    protected override void Execute(IResult inner, ActionExecutionContext context)
    {
        ThreadPool.QueueUserWorkItem(state =&gt;
        {
            inner.Execute(context);
        });
    }

}
//usage:
//[Async]
//public void MyAction() { ... }

/// &lt;summary&gt;
/// Allows to specify a &quot;rescue&quot; method to handle exception occurred during execution
/// &lt;/summary&gt;
public class RescueAttribute : ExecutionWrapperBase
{

    public RescueAttribute() : this(&quot;Rescue&quot;) { }
    public RescueAttribute(string methodName)
    {
        MethodName = methodName;
    }

    public string MethodName { get; private set; }

    protected override bool HandleException(ActionExecutionContext context, Exception ex)
    {
        var method = context.Target.GetType().GetMethod(MethodName, new[] { typeof(Exception) });
        if (method == null) return false;

        try
        {
            var result = method.Invoke(context.Target, new object[] { ex });
            if (result is bool)
                return (bool)result;
            else
                return true;
        }
        catch
        {
            return false;
        }
    }
}
//usage:
//[Rescue]
//public void ThrowingAction()
//{
//    throw new NotImplementedException();
//}
//public bool Rescue(Exception ex)
//{
//    MessageBox.Show(ex.ToString());
//    return true;
//}

/// &lt;summary&gt;
/// Sets &quot;IsBusy&quot; property to true (on models implementing ICanBeBusy) during the execution
/// &lt;/summary&gt;
public class SetBusyAttribute : ExecutionWrapperBase
{
    protected override void BeforeExecute(ActionExecutionContext context)
    {
        SetBusy(context.Target as ICanBeBusy, true);
    }
    protected override void AfterExecute(ActionExecutionContext context)
    {
        SetBusy(context.Target as ICanBeBusy, false);
    }
    protected override bool HandleException(ActionExecutionContext context, Exception ex)
    {
        SetBusy(context.Target as ICanBeBusy, false);
        return false;
    }

    private void SetBusy(ICanBeBusy model, bool isBusy)
    {
        if (model != null)
            model.IsBusy = isBusy;
    }

}
//usage:
//[SetBusy]
//[Async] //prevents UI freezing, thus allowing busy state representation
//public void VeryLongAction() { ... }

/// &lt;summary&gt;
/// Updates the availability of the action (thus updating the UI)
/// &lt;/summary&gt;
public class DependenciesAttribute : Attribute, IContextAware
{

    ActionExecutionContext _context;
    INotifyPropertyChanged _inpc;

    public DependenciesAttribute(params string[] propertyNames)
    {
        PropertyNames = propertyNames ?? new string[] { };
    }

    public string[] PropertyNames { get; private set; }
    public int Priority { get; set; }

    public void MakeAwareOf(ActionExecutionContext context)
    {
        _context = context;
        _inpc = context.Target as INotifyPropertyChanged;
        if (_inpc != null)
            _inpc.PropertyChanged += inpc_PropertyChanged;
    }

    public void Dispose()
    {
        if (_inpc != null)
            _inpc.PropertyChanged -= inpc_PropertyChanged;
        _inpc = null;
    }

    void inpc_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (PropertyNames.Contains(e.PropertyName))
        {
            Execute.OnUIThread(() =&gt;
            {
                _context.Message.UpdateAvailability();
            });
        }
    }
}
//usage:
//[Dependencies(&quot;MyProperty&quot;, &quot;MyOtherProperty&quot;)]
//public void DoAction() { ... }
//public bool CanDoAction() { return MyProperty &gt; 0 &amp;&amp; MyOtherProperty &lt; 1; }

/// &lt;summary&gt;
/// Allows to specify a guard method or property with an arbitrary name
/// &lt;/summary&gt;
public class PreviewAttribute : Attribute, IContextAware
{

    public PreviewAttribute(string methodName)
    {
        MethodName = methodName;
    }

    public string MethodName { get; private set; }
    public int Priority { get; set; }

    public void MakeAwareOf(ActionExecutionContext context)
    {
        var targetType = context.Target.GetType();
        var guard = targetType.GetMethod(MethodName);
        if (guard== null)
            guard = targetType.GetMethod(&quot;get_&quot; + MethodName);

        if (guard == null) return;

        var oldCanExecute = context.CanExecute;
        context.CanExecute = () =&gt;
        {
            if (!oldCanExecute()) return false;

            return (bool)guard.Invoke(
                context.Target,
                MessageBinder.DetermineParameters(context, guard.GetParameters())
            );
        };
    }

    public void Dispose() { }

}
//usage:
//[Preview(&quot;IsMyActionAvailable&quot;)]
//public void MyAction(int value) { ... }
//public bool IsMyActionAvailable(int value) { ... }
</pre>
<p>Source code is here: <a href="https://hg01.codeplex.com/forks/marcoamendola/caliburnmicromarcoamendolafork">https://hg01.codeplex.com/forks/marcoamendola/caliburnmicromarcoamendolafork</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=96&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2010/08/10/a-caliburn-micro-recipe-filters/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>
	</item>
		<item>
		<title>DomusDotNet: a new italian .NET community based in Rome</title>
		<link>http://marcoamendola.wordpress.com/2010/05/21/domusdotnet-a-new-italian-net-community-based-in-rome/</link>
		<comments>http://marcoamendola.wordpress.com/2010/05/21/domusdotnet-a-new-italian-net-community-based-in-rome/#comments</comments>
		<pubDate>Fri, 21 May 2010 17:50:29 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[domusdotnet]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/?p=77</guid>
		<description><![CDATA[Last friday, during the Visual Studio 2010 Community Tour &#8211; Rome, we presented DomusDotNet, a new italian .NET community based in Rome. Our wish is to create a place to share informations, news, technical experiences and meet (both in the web and in the &#34;real&#34; world) other people interested in professional improvement. If you speak [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=77&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://marcoamendola.files.wordpress.com/2010/05/domusdotnet2.png"></a></p>
<p><a href="http://marcoamendola.files.wordpress.com/2010/05/logo_no_pl3.png"></a></p>
<p><a href="http://marcoamendola.files.wordpress.com/2010/05/logo_no_pl4.png"><img style="display:inline;border-width:0;margin:0 15px 0 0;" title="logo_no_pl" border="0" alt="logo_no_pl" align="left" src="http://marcoamendola.files.wordpress.com/2010/05/logo_no_pl_thumb.png?w=240&#038;h=55" width="240" height="55" /></a></p>
<p>Last friday, during the Visual Studio 2010 Community Tour &#8211; Rome, <a href="http://www.domusdotnet.org/chi-siamo.aspx">we</a> presented <a href="http://www.domusdotnet.org">DomusDotNet</a>, a new italian .NET community based in Rome.</p>
<p>Our wish is to create a place to share informations, news, technical experiences and meet (both in the web and in the &quot;real&quot; world) other people interested in professional improvement.</p>
<p><a href="http://marcoamendola.files.wordpress.com/2010/05/logo_no_pl5.png"></a></p>
<p>If you speak Italian, please have a look at our website <a href="http://www.domusdotnet.org/">www.domusdotnet.org</a>; we have been working hard (and late into the night&#8230;) to complete the beta version on schedule, so please don&#8217;t be too severe upon it!</p>
<p>Comments and suggestions are welcome!</p>
<p><a href="http://marcoamendola.files.wordpress.com/2010/05/domusdotnet3.png"><img style="display:block;float:none;border-width:0;margin:0 auto;" title="(some of) DomusDotNet members" border="0" alt="(some of) DomusDotNet members" src="http://marcoamendola.files.wordpress.com/2010/05/domusdotnet_thumb1.png?w=240&#038;h=180" width="240" height="180" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=77&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2010/05/21/domusdotnet-a-new-italian-net-community-based-in-rome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>

		<media:content url="http://marcoamendola.files.wordpress.com/2010/05/logo_no_pl_thumb.png" medium="image">
			<media:title type="html">logo_no_pl</media:title>
		</media:content>

		<media:content url="http://marcoamendola.files.wordpress.com/2010/05/domusdotnet_thumb1.png" medium="image">
			<media:title type="html">(some of) DomusDotNet members</media:title>
		</media:content>
	</item>
		<item>
		<title>Binding to an interface property with WPF</title>
		<link>http://marcoamendola.wordpress.com/2010/03/01/binding-to-an-interface-property-with-wpf/</link>
		<comments>http://marcoamendola.wordpress.com/2010/03/01/binding-to-an-interface-property-with-wpf/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 14:05:00 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/?p=69</guid>
		<description><![CDATA[I received a tweet from José in reply to my comment about the ugliness of the WPF syntax to bind to an interface property, when the interface is explicitly implemented. He reminded me that I tried very hard -and uselessly- to find a workaround for this, and one day the correct syntax just popped out from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=69&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I received a tweet from <a href="http://twitter.com/jfroma">José</a> in reply to my comment about the ugliness of the WPF syntax to bind to an interface property, when the interface is <strong>explicitly </strong>implemented.</p>
<p>He reminded me that I tried very hard -and uselessly- to find a workaround for this, and one day the correct syntax just popped out from a blog I was reading (I can&#8217;t remember who the benefactor was&#8230; I would have liked to thank him here).</p>
<p>Now, the ill-famed syntax:</p>
<p>{Binding Path=(myns:IMyInterface.MyProperty)}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=69&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2010/03/01/binding-to-an-interface-property-with-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>
	</item>
		<item>
		<title>Migration to Caliburn v2</title>
		<link>http://marcoamendola.wordpress.com/2010/01/25/migration-to-caliburn-v2/</link>
		<comments>http://marcoamendola.wordpress.com/2010/01/25/migration-to-caliburn-v2/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 01:28:54 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Caliburn]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/2010/01/25/migration-to-caliburn-v2/</guid>
		<description><![CDATA[After being held captive by the aliens for the last couple months… ehm… what? it’s hardly credible? The plain truth is that I’m having a very busy period at work, so I had to cut hobbies to avoid my daughter stopping calling me “papà” (“daddy”, in italian). Nevertheless, I missed the pleasure of writing something [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=63&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After being held captive by the aliens for the last couple months… ehm… what? it’s hardly credible?</p>
<p>The plain truth is that I’m having a <strong>very</strong> busy period at work, so I had to cut hobbies to avoid my daughter stopping calling me “papà” (“daddy”, in italian).</p>
<p>Nevertheless, I missed the pleasure of writing something here (I have to exercise my English!) so I’ll report about my effort to port a couple project I’m working on to <a href="http://caliburn.codeplex.com/">Caliburn</a> v2. I froze my references to v1.x branch some time ago and deferred the update until today, for the lack of necessary time and because I was afraid to slow down my work with breaking changes.<br />
But all new stuff introduced by <a href="http://devlicio.us/blogs/rob_eisenberg/">Rob</a> in Caliburn trunk was too tempting; plus, I started to be hardly able to follow new Caliburn forum posts about new features, so I finally decided to switch.</p>
<p>It was not hard at all, I have to say.</p>
<p>I still have to refine class and variables names to follow the new “Screens” naming (formerly “Presenters”), but I’ve got the whole thing compiling and passing tests.</p>
<p>For those who are about to start the migration to v2, here is a list of the changes I had to make in my projects. It’s very unlikely an exhaustive list of all changes made to Caliburn, but, since I use a lot of customizations, I think it covers the most frequent issues.</p>
<h3>Modules</h3>
<p>Modules structure was a bit refactored to simplify (I guess) the addiction of configuration parameters to existing and new framework modules; from the user perspective, it means just to choose the new correct base class and the renaming of a couple methods.<br />
I use modules for two distinct goals:</p>
<ul>
<li>provide a way for independent application parts to load and hook itself into the shell without hard-wiring their reference in the main exe</li>
<li>hook some app-specific configuration into the <em>CaliburnFramework</em> static accessor, mimicking other Caliburn’s modules fluent configuration style.</li>
</ul>
<p>For the first need I inherited from <em>ModuleBase;</em><em> </em>for the second goal, I started from <em>CaliburnModule&lt;T&gt;</em> and added an extension method to hook into the fluent configuration. In both cases I had to change the name of <em>Initialize</em> and <em>GetComponents</em> methods into <em>InitializeCore</em> and <em>GetComponentsCore. </em></p>
<pre class="brush: csharp;">

public class MyAppModule : ModuleBase
{
  protected override void InitializeCore(Microsoft.Practices.ServiceLocation.IServiceLocator locator)
  {
  }

  protected override IEnumerable&lt;IComponentRegistration&gt; GetComponentsCore()
  {
    yield return Singleton(typeof(IMyService), typeof(MyService));
  }
}

public class MyFluentModuleConfig : CaliburnModule&lt;MyFluentModuleConfig&gt;
{
  protected override void InitializeCore(Microsoft.Practices.ServiceLocation.IServiceLocator locator)
  {

  }

  protected override IEnumerable&lt;IComponentRegistration&gt; GetComponentsCore()
  {
    yield return Singleton(typeof(IMyOtherService), typeof(MyOtherService));
  }
}

public static class Extenstions
{

  public static MyFluentModuleConfig MyFluentModule(this IModuleHook hook)
  {
    return hook.Module(MyFluentModuleConfig.Instance);
  }
}
</pre>
<h3>Screens</h3>
<p>There was a major refactoring in this area:</p>
<ul>
<li>Naming change (“Presenters” are now “Screens”)</li>
<li>Strong typing of the screen with regard to their “subject”</li>
<li>Strong typing of screen composites based on contained screen</li>
<li>Automatic activation of already opened screen based on their subject</li>
</ul>
<p>In order to accomodate existing code to v2 you have to replace existing class and interfaces following the subsequent scheme:</p>
<ul>
<li><em>IPresenter </em>–&gt;<em> IScreen </em></li>
<li><em>IPresenterHost </em>-&gt;<em> IScreenCollection&lt;IScreen&gt; </em></li>
<li><em>IPresenterManager </em>-&gt;<em> IScreenConductor&lt;IScreen&gt; </em></li>
<li><em>MultiPresenter</em> -&gt; <em>ScreenConductor&lt;IScreen&gt;.WithCollection.AllScreensActive</em></li>
<li><em>MultiPresenterManager </em>-&gt; <em>ScreenConductor&lt;IScreen&gt;.WithCollection.OneScreenActive </em></li>
<li><em>PresenterManager </em>-&gt;<em> ScreenConductor&lt;IScreen&gt; </em></li>
<li><em>Presenter –</em>&gt; <em>Screen </em></li>
</ul>
<p>I closed generic class against IScreen to exactly reproduce the previous behaviour; note that I also chose to use generic version of <em>IScreenCollection </em>and <em>IScreenConductor to match the new signature of screen-related extension functions.</em></p>
<p>I’m still not getting the benefits of strong typing and subject management, I have to refactor my applications in more depth for this.</p>
<h3></h3>
<h3>Application</h3>
<p>I had to fix a trivial signature change in<em> CaliburnApplication.ConfigurePresentationFramework</em> override. In addiction, I changed calls to Presentation Framework module configuration:</p>
<p><em>module.UsingViewStrategy&lt;NoxaViewStrategy&gt;(); </em></p>
<p><em> module.UsingWindowManager&lt;NoxaWindowManager&gt;(); </em></p>
<p>changed to</p>
<p><em> module.Using(c =&gt; c.ViewLocator&lt;NoxaViewStrategy&gt;()); </em></p>
<p><em> module.Using(c =&gt; c.WindowManager&lt;NoxaWindowManager&gt;()); </em></p>
<h3>Framework classes</h3>
<p>Some refactoring was done in the framework internals, so you only have to adjust this classes if you have done customization of the framework behaviour:</p>
<ul>
<li><em>IWindowManager</em> interface: <em>bool isDialog</em> parameter was added in <em>EnsureWindow signature</em></li>
<li><em>IResult</em>: signature of Execute method is changed from<br />
<em>void Execute(IRoutedMessageWithOutcome message, IInteractionNode handlingNode)<br />
</em>to<br />
<em>void Execute(ResultExecutionContext context) </em></li>
<li><em>IResult</em>: signature of <em>Completed </em>event was changed in<br />
<em>EventHandler&lt;ResultCompletionEventArgs&gt;</em></li>
</ul>
<h3>Other random member name changes</h3>
<ul>
<li>RoutedMessageController -&gt; DefaultRoutedMessageController</li>
<li>IBinder -&gt; IViewModelBinder</li>
<li>ViewAttribute: namespace change</li>
<li>IViewStrategy -&gt; IViewLocator</li>
<li>IViewStrategy.GetView –&gt; IViewLocator.Locate</li>
<li>CurrentPresenter property -&gt; ActiveScreen</li>
<li>Presenters property -&gt; Screens</li>
<li>IExtendedPresenter interface -&gt; IScreenEx</li>
<li>Open method -&gt; OpenScreen</li>
<li>Shutdown method -&gt; ShutdownScreen</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=63&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2010/01/25/migration-to-caliburn-v2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>
	</item>
		<item>
		<title>Stock Trader with Caliburn /4</title>
		<link>http://marcoamendola.wordpress.com/2009/10/26/stock-trader-with-caliburn-4/</link>
		<comments>http://marcoamendola.wordpress.com/2009/10/26/stock-trader-with-caliburn-4/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 00:39:00 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Stock Trader with Caliburn]]></category>
		<category><![CDATA[Caliburn]]></category>
		<category><![CDATA[prism]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/2009/10/26/stock-trader-with-caliburn-4/</guid>
		<description><![CDATA[I began to write this post a couple week ago but since then I couldn’t manage to find some spare time to complete it. I hope to remember all the points for which an explanation is worth. This time I’ll port the first real feature of StockTrader to the Caliburn implementation. I’m going to transfer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=55&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I began to write this post a couple week ago but since then I couldn’t manage to find some spare time to complete it. I hope to remember all the points for which an explanation is worth.</p>
<p>This time I’ll port the first real feature of <a href="http://compositewpf.codeplex.com/">StockTrader</a> to the <a href="http://caliburn.codeplex.com">Caliburn</a> implementation. I’m going to transfer the central tab control containing the two main feature of StockTrader and start to restore the first of them.</p>
<p>First of all, I have to restore content areas in the shell, which I initially stripped away. I will replace the custom AnimatedTabControl (that deals with transition animation between the features) with a simple TabControl. </p>
<p>In Prims views are injected at bootstrap time by the various application modules into proper “regions”, that are named areas within the shell view. On the other hand, Caliburn enforce the concept of “Application Model”: a logical representation of the entire application that is aimed to model screen composition and interaction with a non-visual structure.</p>
<p>While leveraging Caliburn’s preferred approach, I want to keep the modular organization of original StockTrader, letting various module to register its features in the shell during bootstrap phase.</p>
<p>Let’s start with “Position” module. I modified PositionModule class, deriving it from CaliburnModule; the class is responsible (both in original and in my version) to register module-specific components and to start its default screen.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> PositionModule : CaliburnModule
{

    <span class="kwrd">public</span> PositionModule(IConfigurationHook hook) : <span class="kwrd">base</span>(hook) { }

    <span class="kwrd">protected</span> <span class="kwrd">override</span> IEnumerable&lt;ComponentInfo&gt; GetComponents()
    {
        <span class="kwrd">yield</span> <span class="kwrd">return</span> Singleton(<span class="kwrd">typeof</span>(IAccountPositionService), <span class="kwrd">typeof</span>(Services.AccountPositionService));
    }

    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Initialize()
    {
        var posSummary = ServiceLocator.GetInstance&lt;PositionSummary.IPositionSummaryPresentationModel&gt;();
        ServiceLocator.GetInstance&lt;IShellPresenter&gt;().Open(posSummary);
    }

}</pre>
<p>I chose to explicitly register in the module class body only AccountPositionService (it could be a remote service), while all other client components are registered declaratively (see <a href="http://caliburn.codeplex.com/wikipage?title=Auto-Registering%20Components">Auto-Registering Components</a> in Caliburn documentation):</p>
<pre class="csharpcode">[PerRequest(<span class="kwrd">typeof</span>(IPositionSummaryPresentationModel))]
<span class="kwrd">public</span> <span class="kwrd">class</span> PositionSummaryPresentationModel : Presenter, IPositionSummaryPresentationModel
{
...
}</pre>
<p>In the Initialize method of the module, an instance of IPositionSummaryPresentationModel is obtained from the container and “opened” in the shell. IShellPresenter is a <a href="http://caliburn.codeplex.com/wikipage?title=IPresenter%20Component%20Model">PresenterHost</a>, so it is responsible of managing multiple content presenters keeping track of the “current” one. </p>
<p>Here is a point where Caliburn and Prism implementation and “philosophy” differs: </p>
<ul>
<li>Prism requires to register views instance into UI regions; even if regions are loosely referenced with strings and views instance are indirectly obtained by presentation model, this approach still seems too view-centric. In addition, the UI composition behaviour is not enforced in the interface of the region: there is no difference between regions supporting single or multiple views; </li>
<li>Caliburn helps to define an application model driving the application parts composition; you don’t have to specify <u>where</u> and the opened presenter is shown: all visualization concerns are taken in account in the views. </li>
</ul>
<p>Let’s see, for example, how to specify the visualization of the presenters managed by the shell:</p>
<p><em>in ShellView.xaml</em></p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TabControl</span> <span class="attr">SelectedIndex</span><span class="kwrd">=&quot;0&quot;</span>
    <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Stretch&quot;</span>
    <span class="attr">ItemContainerStyle</span><span class="kwrd">=&quot;{StaticResource ShellTabItemStyle}&quot;</span>
    <span class="attr">Background</span><span class="kwrd">=&quot;{StaticResource headerBarBG}&quot;</span>

    <span class="attr">ItemsSource</span><span class="kwrd">=&quot;{Binding Presenters}&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">TabControl</span><span class="kwrd">&gt;</span></pre>
<p><em>in TabItemResource.xaml</em></p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;ShellTabItemStyle&quot;</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;{x:Type TabItem}&quot;</span><span class="kwrd">&gt;</span>
    ...
    <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;Header&quot;</span>
            <span class="attr">Value</span><span class="kwrd">=&quot;{Binding DisplayName}&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;ContentTemplate&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ContentControl</span> <span class="attr">cal:View</span>.<span class="attr">Model</span><span class="kwrd">=&quot;{Binding}&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Setter</span><span class="kwrd">&gt;</span>
    ...
<span class="kwrd">&lt;/</span><span class="html">Style</span><span class="kwrd">&gt;</span></pre>
<p>Presenters opened by shell view are displayed within a TabControl; the display name is print in the tab header, while the content of the presenter is put in the content area of the tab. <span class="attr">cal:View</span>.<span class="attr">Model attached property is taking care to peek the correct view to display the presenter.</span></p>
<p>How is the correct view chosen for each presenter? Caliburn follows “Conventions over Configuration” philosophy, defining the concept of ViewStrategy (represented by IViewStrategy interface). This interface is responsible of selecting the right view based on the type of the presentation model class, following an application-wide convention.</p>
<p>The default implementation is well suited for projects with separated namespaces for views and presentation models; Stock Traders, on the contrary, follows the convention of using the namespace to group features, thus having presentation model in the same namespace of its corresponding view.<br />
  <br />To use this convention I subclassed the default convention:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> StockTraderViewStrategy : DefaultViewStrategy
{
    <span class="kwrd">public</span> StockTraderViewStrategy(IAssemblySource assemblySource, IServiceLocator serviceLocator)
        : <span class="kwrd">base</span>(assemblySource, serviceLocator) { }

    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">string</span> MakeNamespacePart(<span class="kwrd">string</span> part)
    {
        <span class="kwrd">return</span> part;
    }

    <span class="kwrd">protected</span> <span class="kwrd">override</span> IEnumerable&lt;<span class="kwrd">string</span>&gt; ReplaceWithView(Type modelType, <span class="kwrd">string</span> toReplace)
    {
        <span class="rem">// MyNamespace.SomethingPresentationModel -&gt; MyNamespace.SomethingView</span>
        <span class="rem">// or MyNamespace.SomethingPresenter -&gt; MyNamespace.SomethingView</span>
        <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(toReplace))
            <span class="kwrd">yield</span> <span class="kwrd">return</span> modelType.Namespace + <span class="str">&quot;.&quot;</span> + modelType.Name.Replace(toReplace, <span class="str">&quot;View&quot;</span>);

    }
}</pre>
<p>and registered it at application startup:</p>
<p><em>in App.xaml.cs</em></p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> ConfigurePresentationFramework(Caliburn.PresentationFramework.PresentationFrameworkModule module)
{
    module.UsingViewStrategy&lt;Infrastructure.StockTraderViewStrategy&gt;();
}</pre>
</p>
<p>&#160;</p>
<p>Finally, I have the first module loading and displaying its default screen in the shell:</p>
<p><a href="http://marcoamendola.files.wordpress.com/2009/10/image.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://marcoamendola.files.wordpress.com/2009/10/image_thumb.png?w=447&#038;h=268" width="447" height="268" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=55&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2009/10/26/stock-trader-with-caliburn-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>

		<media:content url="http://marcoamendola.files.wordpress.com/2009/10/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF binding to a Windsor proxied component</title>
		<link>http://marcoamendola.wordpress.com/2009/09/18/wpf-binding-to-a-windsor-proxied-component/</link>
		<comments>http://marcoamendola.wordpress.com/2009/09/18/wpf-binding-to-a-windsor-proxied-component/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 22:20:04 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[wpf binding proxy dynamicproxy windsor aop interception]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/?p=40</guid>
		<description><![CDATA[WPF binding is very powerful but has some annoying issues. This time I faced with a well known one: binding to an explicitly implemented interface member doesn&#8217;t work: public interface IFoo { int BarsCount {get;} } public class Foo:IFoo { int IFoo.BarsCount { return 3; } } &#60;TextBox DataContext=[set to some Foo instance] Text={Binding Path=BarsCount} [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=40&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>WPF binding is very powerful but has some annoying issues. This time I faced with a well known one: binding to an <strong>explicitly</strong> implemented interface member doesn&#8217;t work:</p>
<pre class="brush: csharp;">
public interface IFoo {
int BarsCount {get;}
}

public class Foo:IFoo {
int IFoo.BarsCount {
return 3;
}
}
</pre>
<pre class="brush: xml;">

&lt;TextBox DataContext=[set to some Foo instance] Text={Binding Path=BarsCount} /&gt;
</pre>
<p>This way the textbox is <span style="text-decoration:underline;">not</span> filled; while annoying, it could be fixed implementing interface <strong>implicitly</strong>:</p>
<pre class="brush: csharp;">

public class Foo:IFoo {
public int BarsCount {
return 3;
}
}
</pre>
<p>Sometimes it is not possible, because we can’t control concrete class implementation. This is the case when the concrete class is dynamically generated proxy.</p>
<p>In a project of mine I use <a href="http://castleproject.org/container/index.html">Castle Project’s Windsor Container</a>, that relies on <a href="http://www.castleproject.org/dynamicproxy/index.html">Castle DynamicProxy</a> for its AOP/intercepion features (which I use for cross-cutting concern implementation).<br />
In this project all the presenters are registered in the container with related interfaces; when I configure an interceptor for a presenter, the concrete class returned by the container is not the registered implementation, but a dynamically generated proxy (implementing the registered interface) forwarding all method calls to a wrapped instance of my hand-written presenter (thus allowing methods interception).</p>
<p>This interception style is called Interface Proxy  (see excellent <a href="http://kozmic.pl">Krzysztof Koźmic</a> <a href="http://kozmic.pl/archive/2009/04/27/castle-dynamic-proxy-tutorial.aspx">tutorial</a> on Castle DynamicProxy proxy capabilities).</p>
<p>This way, however, previously working binding to the presenter stops running: presenter instance no longer has expected (at least by WPF) properties in its public interface.</p>
<p>The solution I found (yet not very general) is to leverage another interception style, Class Proxy, used by Windsor when a component is registered without a corresponding interface. In this scenario, the generated proxy is a dynamically generated subclass of the concrete component registered; this way only virtual method could be intercepted, but the public interface of the component is preserved (and so the WPF binding operation).</p>
<p>The choice of the interception style is taken by a well defined (and pluggable) Windsor component: IProxyFactory. So I implemented a custom IProxyFactory, inheriting the default one and altering its behavior when the registered component is decorated with a certain custom attribute; this attribute specifies that a Class Proxy style interception should be used. Here the implementation:</p>
<pre class="brush: csharp;">

[AttributeUsage(AttributeTargets.Class)]
public class ForceClassProxyAttribute : Attribute { }

//Force class proxy if service implementor is decorated with ForceClassProxyAttribute
//Is a workaround for WPF binding not seeing interface members
public class WindsorProxyFactory : DefaultProxyFactory
{
public override object Create(Castle.MicroKernel.IKernel kernel, object target, Castle.Core.ComponentModel model, Castle.MicroKernel.CreationContext context, params object[] constructorArguments)
{
if (this.ShouldForceClassProxy(model, target))
return CreateForcingClassProxy(kernel, target, model, context, constructorArguments);
else
return base.Create(kernel, target, model, context, constructorArguments);
}

protected virtual object CreateForcingClassProxy(Castle.MicroKernel.IKernel kernel, object target, Castle.Core.ComponentModel model, Castle.MicroKernel.CreationContext context, params object[] constructorArguments)
{
object proxy;

IInterceptor[] interceptors = ObtainInterceptors(kernel, model, context);

ProxyOptions proxyOptions = ProxyUtil.ObtainProxyOptions(model, true);
ProxyGenerationOptions proxyGenOptions = CreateProxyGenerationOptionsFrom(proxyOptions);

CustomizeOptions(proxyGenOptions, kernel, model, constructorArguments);

Type[] interfaces = proxyOptions.AdditionalInterfaces;
proxy = generator.CreateClassProxy(model.Implementation, interfaces, proxyGenOptions,
constructorArguments, interceptors);

CustomizeProxy(proxy, proxyGenOptions, kernel, model);

return proxy;
}

protected bool ShouldForceClassProxy(Castle.Core.ComponentModel model, object target)
{

return model.Implementation
.GetCustomAttributes(typeof(ForceClassProxyAttribute), true)
.Any();
}
}
</pre>
<p>Then I simply provide this custom IProxyFactory implementation when container instance is created:</p>
<pre class="brush: csharp;">

var container = new WindsorContainer(new IniziativeInformatiche.Core.WindsorProxyFactory());
</pre>
<pre></pre>
<p>Comments and suggestions are welcome, if someone will ever get here <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><em>Edit:</em></p>
<p>It seems that binding to interface members could be done with the syntax:</p>
<pre class="brush: xml;">

{Binding Path=(local:IFoo.BarsCount)}
</pre>
<p>I should better investigate, even though this way I should fix <span style="text-decoration:underline;">all</span> existing views…</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=40&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2009/09/18/wpf-binding-to-a-windsor-proxied-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>
	</item>
		<item>
		<title>Stock Trader with Caliburn &#8211; code repository</title>
		<link>http://marcoamendola.wordpress.com/2009/09/15/stock-trader-with-caliburn-code-repository/</link>
		<comments>http://marcoamendola.wordpress.com/2009/09/15/stock-trader-with-caliburn-code-repository/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 16:44:00 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/?p=36</guid>
		<description><![CDATA[I set up a project repository to publish the code: http://code.google.com/p/caliburn-stock-trader/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=36&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I set up a project repository to publish the code:<br />
<a style="text-decoration:none;" href="http://code.google.com/p/caliburn-stock-trader/">http://code.google.com/p/caliburn-stock-trader/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=36&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2009/09/15/stock-trader-with-caliburn-code-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>
	</item>
		<item>
		<title>Stock Trader with Caliburn /3</title>
		<link>http://marcoamendola.wordpress.com/2009/09/14/stock-trader-with-caliburn-3/</link>
		<comments>http://marcoamendola.wordpress.com/2009/09/14/stock-trader-with-caliburn-3/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 00:38:59 +0000</pubDate>
		<dc:creator>Marco Amendola</dc:creator>
				<category><![CDATA[Stock Trader with Caliburn]]></category>
		<category><![CDATA[Caliburn]]></category>
		<category><![CDATA[prism]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://marcoamendola.wordpress.com/?p=23</guid>
		<description><![CDATA[It&#8217;s time to give the project some love, and put down some code to fix ideas.I created a new solution and started to transfer feature one after one. I kept the overall structure of the original project  to simplify comparison between the two implementation and because I found it quite neat. The two project created are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=23&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time to give the project some love, and put down some code to fix ideas.I created a new solution and started to transfer feature one after one.</p>
<p>I kept the overall structure of the original project  to simplify comparison between the two implementation and because I found it quite neat. The two project created are the exe project, containing the shell, and an Infrastructure library, containing common interfaces and classes (just like the original StockTraderRI):</p>
<p><img class="size-full wp-image-24 aligncenter" title="RI_prj_13092009_234043" src="http://marcoamendola.files.wordpress.com/2009/09/ri_prj_13092009_234043.jpg?w=295&#038;h=142" alt="RI_prj_13092009_234043" width="295" height="142" /></p>
<p>The first step I decided to take is to setup the project structure and have the shell starting.</p>
<p>Original application doesn&#8217;t have a presenter for the shell, so I created an IShellPresenter interface in Infrastructure proejct (I&#8217;ll need to reference it in the modules) and an implementation in the exe project:</p>
<p><img class="aligncenter size-full wp-image-26" title="RI_shellpres_14092009_14242" src="http://marcoamendola.files.wordpress.com/2009/09/ri_shellpres_14092009_142421.jpg?w=451&#038;h=108" alt="RI_shellpres_14092009_14242" width="451" height="108" /></p>
<p>The <a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=Auto-Registering%20Components">Singleton</a> attibute is used to auto-register the class within the container with a singleton lifestyle; the View attribute indicates Caliburn <a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=View%20Strategies">which view</a> should be used to &#8220;visually represent&#8221; the presenter.<br />
The markup for the shell view (ShellView.xaml) was only slightly modified to remove reference to CompositeWPF library and to custom controls,  whose features will be implemented later.</p>
<p>To have the first window running, I had to configure Caliburn. I chosen to derive my App class from CaliburnApplication, so I just had to indicate the  root model for the application:</p>
<p><img class="aligncenter size-full wp-image-27" title="RI_app_14092009_15520" src="http://marcoamendola.files.wordpress.com/2009/09/ri_app_14092009_15520.jpg?w=473&#038;h=144" alt="RI_app_14092009_15520" width="473" height="144" /></p>
<p>That&#8217;s all. I can start the application and the main window shows as well (with no content, for now):</p>
<p style="text-align:center;"><img class="aligncenter size-medium wp-image-28" title="RI_shell_14092009_21739" src="http://marcoamendola.files.wordpress.com/2009/09/ri_shell_14092009_21739.jpg?w=300&#038;h=185" alt="RI_shell_14092009_21739" width="300" height="185" /></p>
<p style="text-align:left;">Next time I&#8217;ll add the first real feature of the app; since all feature in original StockTraderRI resides in modules, I also have to deal with module loading and configuration.<br />
I also should setup an online code repository to share the code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcoamendola.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcoamendola.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcoamendola.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcoamendola.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcoamendola.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcoamendola.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcoamendola.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcoamendola.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcoamendola.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcoamendola.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcoamendola.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcoamendola.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcoamendola.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcoamendola.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcoamendola.wordpress.com&amp;blog=1172472&amp;post=23&amp;subd=marcoamendola&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcoamendola.wordpress.com/2009/09/14/stock-trader-with-caliburn-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e9b297da8888ab0cff3fe41ca1c4c793?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marcoamendola</media:title>
		</media:content>

		<media:content url="http://marcoamendola.files.wordpress.com/2009/09/ri_prj_13092009_234043.jpg" medium="image">
			<media:title type="html">RI_prj_13092009_234043</media:title>
		</media:content>

		<media:content url="http://marcoamendola.files.wordpress.com/2009/09/ri_shellpres_14092009_142421.jpg" medium="image">
			<media:title type="html">RI_shellpres_14092009_14242</media:title>
		</media:content>

		<media:content url="http://marcoamendola.files.wordpress.com/2009/09/ri_app_14092009_15520.jpg" medium="image">
			<media:title type="html">RI_app_14092009_15520</media:title>
		</media:content>

		<media:content url="http://marcoamendola.files.wordpress.com/2009/09/ri_shell_14092009_21739.jpg?w=300" medium="image">
			<media:title type="html">RI_shell_14092009_21739</media:title>
		</media:content>
	</item>
	</channel>
</rss>
