-
Web Client Software Factory Automation
5 Comments(This post was going to be posted a few weeks ago so the images are a bit outdated but the content is the same that you will see in latest drops)
I’ve been working on the Guidance Packages for the Web Client Software Factory. If you read this blog you probably know what is this all about. If not, in short we are adding functionality to Visual Studio 2005 to make the developer life easier
In the case of the Web Client Software Factory (WCSF from now on), in this first release we are targeting modularity, security and a testable programming model among other things.
In this drop you will see something really close to what we will be shipping.
Let’s deep into what the Guidance Package brings to the table.
First of all we will create a new web application and let’s call it “OrderManager”
Before creating the actual solution the recipe asks for a few things:
- Where do you have the binaries (the new CompositeWeb Application Block and Enterprise Library Jan 2006)? I have compiled them and put them in c:\Lib
- What’s the .net namespace that you will use for this application?
This is what we get after the solution is created:
In a nutshell:
- A Website containing a default page, a default master page a default theme, references to the application blocks and EntLib.
- A Shell module with a ModuleInitializer. This module will be used for pages that lives in the website root and some services initialization (like the SiteMapBuilderService and the EnterpriseLibraryAuthorizationService)
If you run the website at this point you will get this:
Adding a module…
We can add our first module by doing a right-click on the Modules solution folder.
The following feature is part of the “new generation” of guidance packages. Before you commit your module creation you can see what is going to happen to your solution (one project will be created, a folder on the website will be created, etc.)
The options are:
- What’s the website project where you want to plug this module?
- Do you want to have a different name for the folder on the website?
- Finally we have an “Add test project” option that will create a VSTS test project for you with the Test Fixture for the DefaultViewPresenter
If we run the solution again we will see the new module plugged in the website
The cool thing about this is the loosely coupled model to add nodes to the sitemap. The OrdersModuleInitializer has a template method to register the sitemap nodes that the module will provide. Here we register the module site map node:
protected virtual void RegisterSiteMapInformation(ISiteMapBuilderService siteMapBuilderService)
{
SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Orders", "~/Orders/Default.aspx", "Orders");
siteMapBuilderService.AddNode(moduleNode);
}
(A nice addition to this would be a service that reads from the module web.config file and creates the corresponding nodes)
Adding a web page…
We can create pages for our module by right clicking on the “Orders” module folder on the website
We are leveraging the MVP (Model-View-Presenter) pattern. If you used the Smart Client Software Factory you should be familiar with this, if not you can read more about it here and here.
The view is separated in three parts:
- The OrderListPresenter holds the logic for the view and has access to the view via an interface (IOrderList). This increases the testability of your applications. The idea is to have the view do almost nothing. Its responsibility will be to show stuff that the presenter wants and notify the presenter of user events (clicks, selects, etc.).
- The IOrderList interface is the contract for the Presenter
- Finally the OrderList.aspx + .cs is the actual implementation of the interface that will show things on the webpage.
If we want to show this view in the navigation control (in this case a TreeView) we would add the following code to the RegisterSiteMapInformation:
protected virtual void RegisterSiteMapInformation(ISiteMapBuilderService siteMapBuilderService)
{
SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Orders", "~/Orders/Default.aspx", "Orders");
siteMapBuilderService.AddNode(moduleNode);
SiteMapNodeInfo orderListNode = new SiteMapNodeInfo("OrderList", "~/Orders/OrderList.aspx", "Order List");
siteMapBuilderService.AddNode(orderListNode, moduleNode);
}
Running the site at this instance will show the following:
Implementing a view and its presenter…
We will implement the basic things to show a list of orders on the web page.
Let’s start from the presenter logic. Note: If we were using TDD we would start from a test that would be called “ShowOrderListOnViewLoaded()”.
public class OrderListPresenter : Presenter<IOrderList>
{
public override void OnViewLoaded()
{
// TODO: Implement code that will be executed every time the view loads
List<Order> orders = new List<Order>();
orders.Add(new Order("Order 1", 12300, DateTime.Now));
orders.Add(new Order("Order 2", 200, DateTime.Now));
orders.Add(new Order("Order 3", 100000, DateTime.Now));
View.Orders = orders;
}
We are setting the Orders of the View property. The View property belongs to the base Presenter class and it provides access to the view via its interface (IOrderList).
That means that we need to add the Orders property on the interfacepublic interface IOrderList
{
IList<Order> Orders { set; }
}
Finally we will implement it on the OrderList.aspx:
We can use the smart tag on the interface to generate the required interface contract:
Then we add the GridView to the page
And finally implement the interface:
public IList<Order> Orders
{
set
{
GridView1.DataSource = value;
GridView1.DataBind();
}
}
Running the site again…
That’s it. We have a Web application that leverages:
- MVP design pattern
- The best practices for ASP.Net
- Exception handling using Enterprise Library 2006
- Authorization infrastructure also from Enterprise Library
- Dependency Injection
- And a lot of other things that you will discover…
Lastly, if you are wondering about “Why use GridView.DataSource and not some DataSourceControl like ObjectDataSource?”
We are shipping with the factory a DataSourceControl called ObjectContainerDataSource that will work very well in these scenarios. Mariano has an interesting post. -
5 Comments:
Leave a comment
Your email address will not be published.
el perucho said on January 9, 2007:
Matias greetings, I am trying to learn to use the CAB and the SmartClient, but really me this costing too much work, already makes the CAB laboratories and I am almost just as as it initiates. My question is the following one does not exist a code generator that the WorkItems makes… I see in your blog images you that have something is called “Guindance Packagesâ€/“SmartCliente Developer†and it has peculiar (that to me is a generator of code for SmartClient (Windows-form).
Greetings and excuse by my English is generated by the Google Translator.
matiaswoloski said on January 10, 2007:
Podes escribirme en español si queres.
Gracias
Matias
http:// said on February 9, 2007:
Hi Matias,
Firstly would congratulate on the release of webclientfactory… Well we as a team of developers started to use Smart Client Factory since Sep’06 and now have reached a level where we are quite comfortable in the same.
After the release of webclientfactory, we started the next hurdle which was making the web component for our Smart Client and in the process shall re-use Service-Agents and Service Proxies. But we are having following issues:
1) The Enterprise Library dll has changed (version 2.0.1.0), And it works for Web Client but it does not works for Smart Client.
2) The exact problem is in the file… Command.cs, CommandWithCallback in service proxies project which has reference to Microsoft.Practices.EnterpriseLibrary.ExceptionHandling. Thats what am guessing…
Kindly look into this problem, i cant see any messageboard where i can post the problems. Please do refer some.
Wali.
matiaswoloski said on February 10, 2007:
Hi Wali,
We decided to strong name the entlib dlls and include them in the MSI. However the functionallity is the same in 2.0.0.0 and 2.0.1.0. The only difference is that the latter is signed.
You can replace one with the other. We are starting SCSF v2 so expect the new version to use 2.0.1.0 also.
Finally, webclient factory forums are http://www.codeplex.com/websf/Thread/List.aspx
Thanks
Matias
http:// said on February 10, 2007:
Hi Again Matias,
Thanks for the quick reply. I did found the Message Board though. Well i understood about the
Enterprise Lib DLL’s but still situation remains the same for me. When i replaced that DLL in my
smartClient, its not working.
1) As far as i understood we are supposed to use the same Enterprise Lib dlls(i.e. 2.0.1.0) for the
Smart Client and and Web Client. Please comment.
2) We made seperate Business Layer which has Business Entities, Service Proxies, Service Agents and
Translators as seperate projects. UI Layer consume these services, through Service Agents( After
registering the same in UI layer). Now We want to use the same Business Layer through the Web
Client. For that we have to have only one reference of Eterprise Lib, Object Builder Etc in this
layer. And both Smart Client and Web Client shall use this layer.
The problem here is we were using Ent Lib DLL version 2.0.0.0 in Business Layer for smart client
(till now) and as now for Web Client the version has changed… so we cannot use the business layer
for both now.
For version 2.0.1.0
1) Smart client not working, Web Client working.
For version 2.0.0.0
1) Smart client working, Web Client not working.
So my questions are
1) Do i need to do something else in my UI/Business layer to use the new Strongly Typed Ent Lib dll
(version 2.0.1.0)?
2) Well as you already mentioned that there is no functional change in this version, Should Smart
Client behave differently still?
3) Shall i have to wait for another release of Smart Client and then use Enterprise Lib (version
2.0.1.0) DLL?
Is there any Demo Application which shall show the usage of ServiceProxy/ServiceAgent from Smart
Client as well as Web Client? I hope am not asking for a lot…
It shall be very helpful if u would recommend any blog/post/white paper regarding the same. One last
question, when shall be the next release for the Smart Client and what shall be the major
changes/Improvisations.
Wali.