In my previous post, I tried to implement the Presentation Model (PM) using CAB, which is an alternate way besides MVP to improve the MVC pattern.
Since I liked the idea that WorkItem is the container of use case, here I show the use cases again.
Therefore I must have 4 WorkItem sub classes. These classes contain Views. The views share one PM and pull data from it.
Last time, the biggest trouble I had is how to pass the PM instance, because I tried to use the [Dependency] attribute to inject the object and tried to store it in WorkItem's State. Both are bad ideas. The [Dependency] attribute is mainly for ObjectBuilder internal use. And inject into WorkItem's State just dose not work.
Now I realized that the PM actually can be treated as a service. Using the [Service] attribute and the [ServiceDependency] attribute, the structure started looking really better now.
1. Define the PM as service
[Service]
public class CustomerPMController: ICustomerDetailView, ICustomerListView
{
}
2. Access PM as service dependency
public partial class CustomerListView : TitledSmartPart
{
private ICustomerListView controller = null;
[ServiceDependency(Required = true, Type = typeof(CustomerPMController))]
public ICustomerListView Controller
{
set { controller = value; }
}
....
}
That's it. Everything is declarative and objects are built by OB through attribute.
A very small thing not 100% statisfied is that I have to use
[ServiceDependency(Required = true, Type = typeof(CustomerPMController))]
instead of
[ServiceDependency(Required = true, Type = typeof(ICustomerListView))]