locked
Shared code between server and silverlight - how to reference client assemblies RRS feed

  • Question

  • Hi experts.

    I am sharing code between Silverlight and Server. Silverlight MainViewModel is  a  big nested class containing my business data (collections of hierarchies of my business object shared between SIlverlight and Server). MainViewModel is a singleton so I can easy reference it from any other Silverlight class (NOT shared code). MainViewModel contains references to web services. That services are sending shared code business objects back and force.

    I would like to call these services from my Business Objects (shared code), but I cannot get reference to the MainViewModel class. MainViewModel references Web Services so I cannot reference it to get static MainViewModel instance from my shared code library. 

    How can i solve it: Declare events in my business objects and to listen to them and then call mainViewModel Web Services methods to save, update, delete data. But it is very cumbersome. I would like to call thees methods directly. Do you know, how to solve this? Thank you very much.

    Tom

     

     

    Friday, September 21, 2012 10:37 AM

Answers

  • thank you very much. I know this. I have already solved my problem. All my ViewModel classes are based on an abstract class ViewModel base. So I have declare an virtual method SEtMainViewModel which is receiving an object declared via an interface IMainViewModel. All my classes are overriding this virtual method so I am now able to set a reference to the MainViewModel when these objects are deserialized on the client. But I still have a one question. Is it possible to declare handler to the ONDESERIALIZED in another classs? Not the one when the event is rising.

    Thank you very much.

     

    Tom

    Tuesday, September 25, 2012 7:56 AM

All replies

  • I have discovered that I can declare an interface of my MainViewModel in another project. Both Silverlight and Shared libraries will be Dependant on that project. So I can declare a property of that interface type in every business class that need communication. But still I don't know how to set this property automatically to that MainViewModel singleton. Yes I can do it when the object arrives via web service but this is very complicated, because my business object usually contains deep hierarchy of another business objects. So I would need to traverse them. I would like to use an event when objects are deserialized on the client. But I don't know how.

    Thank you again Tom

    Friday, September 21, 2012 12:18 PM
  • Hi Tom,

    Sorry I feel a bit confused with your issue although you tell so much.

    I would like to use an event when objects are deserialized on the client. But I don't know how.

    For Serizlization and Deserilization in WCF, you can add [DataContract] above the class and [DataMember] above its properties. For more details, please refer to: http://msdn.microsoft.com/en-us/library/ms731073.aspx 

    Best Regards,

    Tuesday, September 25, 2012 7:20 AM
    Moderator
  • thank you very much. I know this. I have already solved my problem. All my ViewModel classes are based on an abstract class ViewModel base. So I have declare an virtual method SEtMainViewModel which is receiving an object declared via an interface IMainViewModel. All my classes are overriding this virtual method so I am now able to set a reference to the MainViewModel when these objects are deserialized on the client. But I still have a one question. Is it possible to declare handler to the ONDESERIALIZED in another classs? Not the one when the event is rising.

    Thank you very much.

     

    Tom

    Tuesday, September 25, 2012 7:56 AM