views:

160

answers:

3

Hello.

I'm developing an three layer ASP.NET application with C# and Visual Studio 2008 SP1. I'm using WebForms.

I'm wondering to convert that application to a Silverlight application. Maybe I can reuse a lot of code of ASP.NET layer.

What do you think about?

+3  A: 

Assuming you have the typical presentation, business logic, and data layers, and also assuming that you have separated your code diligently into these layers, you should be able to replace your Web Forms with a Silverlight interface and leave your BL and DAL intact.

Real projects tend to be somewhat messy, however, making such a transition more difficult. If you're using SqlDataSource you might have problems.

Andy West
+1 - ASP.NET projects can be messy :)
slugster
I'm using Entity Framework to access a SQL Server 2008 database. Why did yoy say that I'm going to have problems if I use SqlDataSource?
VansFannel
+2  A: 

Those are some good points @Andy, and to expand on what he said:

i'm doing that very same thing right now. Because i have a rather comprehensive business layer, i have been able to do a lot of work (a couple of weeks worth), and in that time i have only had to add one function to that business layer. This is important because it reduces the amount of testing required. It also makes any remaining testing easier as it is easier to compare the output of the old version of the application with the new version.

One pattern that really helped to achieve this was the facade pattern. I built a WCF layer that sits over top of the business layer, and by using the facade pattern i can return results that are more suitable for the new silverlight interface, without interfering with the business layer.

It is most likely though that your new UI will have a drastically different architecture than the ASP.NET version. You will be able to achieve a far cleaner separation between UI, code and data. Some of the ASP.NET code that i was quite proud of looks positively mangy next to the equivalent silverlight code. Be prepared to chop your old code up, and eliminate those business rules from the immediate code behind :)

slugster
Facades are definitely a good idea, you can even have another layer (class) on the WCF side e.g. UIApplicationServices which interfaces with the business layer but doesn't assume any specific UI. Then the WCF service facades talk to the UIApplicationServices to provide services to the UI (be it ASP.Net, Silverlight, WinForms, etc). The cool thing about using something like UIApplicationServices is that you can call directly from webform (e.g. populating drop down list on first page load) and then consume the other operation using AJAX.
Jason Roberts
+1  A: 

If you're goal is simply to replicate the UI behaviour as delivered by ASP.NET then yes assuming good partitioning you could re-use quite a bit of code. You'd have ask why you would want to do that though.

On the other hand if the goal is to provide a much richer interactive experience to the user then its likely that you'll find even a well designed business layer just doesn't behave the way such a radically different UI needs it to.

AnthonyWJones
Thank you. Now, I have to learn Silverlight 3.
VansFannel