views:

39

answers:

2

Hi,

Lets assume that I have my own business layer containing my business objects and my business services. And I have decided to create a "SilverLight Business Application" (with SL v 4.0) and I want to use my already used Business Layer from the SL application I plan to develop.

I know that I cannot include a project which is not a SL project.

Can you pls advice me hos I can achieve this?

Thanks

+2  A: 

Since SL != .NET, you'll need to compile them in a Silverlight assembly, using the Silverlight compiler. In other words, you can't directly consume them without a little trickery.

One option is to create a Silverlight project, then use file-linking to share code-files from the .NET project (wihtout duplicating them). A normal project owns the files contained within it, but a "linked" file is included for compilation without being fully owned by the project. Files are linked by going to "Add File > Add Existing File" dialog, look to the bottom right, and you'll see that you can "link" an existing file.

What you can then do:

  • Have your normal .NET project, with your .cs files
  • Have a Silverlight project, which links to your first projects code files

When you compile the Silverlight project it will treat the linked files as though they belong to the SL project (but on your drive there is only a single copy, inside your .NET project).


A challenge you may run into is that not all .NET types are supported in Silverlight, so if your business objects contain these then your .NET code might not compile under silverlight. You can use pre-compiler directives to have 2x method signatures for these cases: 1x .NET, and 1x SL compatible. Your would set the directive (ie: Silverlight==True) and the compiler would choose one or the other.

For example:

#IF SILVERLIGHT
    public void SomeMethod(SilverlightType someParam)
#ELSE
    public void SomeMethod(SomeDotNetType someParam)
#ENDIF

Here's a link with a walkthrough from Rocky Lhotka (author/CSLA.net framework designer). He mentions using linked files and/or partial classes to selectively compile for each platform.

STW
A: 

If you use RIA services, you will find you can do all sorts of clever tricks server side (including linking to full .Net libraries). It is only client side that Silverlight-only libraries must be used.

The challenge with Silverlight is actually to expose appropriate business rules, to the client side, via RIA attribute mark-up and custom validators.

You will find in practice that the client side rules can differ a little from the server side anyway, so a little rethinking of what actually needs validating on the client is not a bad thing.

Enough already