Eco Silverlight–client and server side–how is it supposed to work
The question on the forum was “So what is on the Eco Service side? What are the steps going to be to make a SL Eco project work? Is there a description anywhere of what the plans are for this to work?”
And this is the answer as it stands today.
There is no Silverlight wizard available (yet) so you do need some hacking to get started – just copy stuff from here…
(Everything here is for Silverlight 4)
#1 Pick New Solution and create a new EcoProject in dll using the standard wizard, also choose to have a Server for persistence – I took Windows application below:
#2 Right-click the solution and pick “Add new Project” - Pick a Silverlight Application (standard on all options you need to set):
#3 Right—click solution and pick “Add new project” again – this time pick a Silverlight Class Library – Name it SLEcoSpaceAndModel
#4 Delete the default Class1 in SLEcoSpaceAndModel and add “Existing Item” – we are going to add a link to the EcoProject1.ecomdl file. Make sure it is a link and not a copy:
When we have gotten this far you can test that the “Modlr plugin – CodeGen function” has been extended to find ecomdl file links in Silverlight projects. This shows by modeling a few classes and clicking update code:
You will find that the generated code is also maintained as links in the SLEcoSpaceAndModel project – this is only due to the fact that this project contains a file link to the EcoProject1.ecomdl file.
We want to have it this way since we cannot reuse the EcoProject1.Model assembly in a Silverlight application since it is NOT a Silverlight project (EcoProject1.Model is not SL) – and we do not want it to be a Silverlight project since we want to let our server side code – and possibly other consumers – share a normal .net assembly (not Silverlight).
#5 We now need an EcoSpace instance in Silverlight – I will add it in the SLEcoSpaceAndModelAssembly – you could add it in an assembly of its own – but there is not much point unless you will have multiple Silverlight frontends that all are going to use a common model.
I suggest that you just copy much of this code into a new file:
You need to add references to ECO Silverlight assemblies, to all the Silverlight assemblies that will use ECO:
And The SilverlightApplication assembly needs also a reference to the SLEcoSpaceAndModel assembly.
Then we can initialize an EcoSpace instance, I choose to do it in the MainPage.xaml.cs:
And to test things out I use a ViewModelUserControl:
And when using rendered ViewModels we also need to init them:
Implement the button event handlers:
And the result is a silverlight app that shares model and user code implementations with the server: