locked
Questions about developing a HTML/JS + C# app RRS feed

  • Question

  • I currently am working with an HTML/JS app but have been trying to write easily reusable components.  So am trying to keep UI display logic in HTML and JS and keep back end logic in C# libraries accessed through winMD interfaces. This allows back end logic to be independent of whether an app uses XAML or HTML for the UI.   The only drawbacks that I can see right now are that using HTML/JS requires extra coding to create the winMD in-betweens and that you are limited to only passing WinRT types.  So far I find it difficult to move all back end logic to C# but certain components are possible.

    Is this setup a good idea?  Are there any long term problems that could arise with this structure for code?  Is there no way to create custom classes in C# that are passable to JS?

    Thanks


    -Jeff

    Wednesday, March 28, 2012 11:21 PM

Answers

  • Hi,

    HTML5/CSS3/JS is easier and more flexible for you to develop UI. You can wrap up backend logic into WinRT component written by C#,VB, C++. The separation of business logic from UI is good design. You can define custom class in C#, VB, or C++ WinRT and then consume it in Javascript UI.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Robin_YangModerator Thursday, March 29, 2012 2:35 AM
    • Marked as answer by jfrtc Thursday, March 29, 2012 6:43 PM
    Thursday, March 29, 2012 2:34 AM
    Moderator
  • I got you Jeff,

    Yes you have to ensure anything that is exposed is a WinRT type.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 29, 2012 6:25 PM
    Moderator

All replies

  • Hi,

    HTML5/CSS3/JS is easier and more flexible for you to develop UI. You can wrap up backend logic into WinRT component written by C#,VB, C++. The separation of business logic from UI is good design. You can define custom class in C#, VB, or C++ WinRT and then consume it in Javascript UI.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Robin_YangModerator Thursday, March 29, 2012 2:35 AM
    • Marked as answer by jfrtc Thursday, March 29, 2012 6:43 PM
    Thursday, March 29, 2012 2:34 AM
    Moderator
  • Jeff,

    Think of the WinMD component as your class implementation... simply provide methods on that interface for your class methods and properties.  Follow?

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 29, 2012 1:34 PM
    Moderator
  • I think my original post wasn't very clear.  What I am thinking about is to have another layer after the WinMD class in order to break up business logic into smaller chunks that are easier to manage and also reusable for XAML/C#.

    Here is an example of the structure:

    JavaScript:

    var data = GetData();

    //do something with the data

    WinMD C#:

    public string GetData()
    {
       ...
       OpenConnection();
       Data data = await TransferData();
       CloseConnection();
    
       //format to JS consumable data structure
       return data.ConvertToJS();
    }

    Regular C# Library

    public void OpenConnection() {...}
    
    public void CloseConnection() {...}
    
    public async Data TransferData() {...}

    If I put OpenConnection, CloseConnection and TransferData in the WinMD level then it is no longer inheritable and can't expose methods which return non-WinRT types.  Also I don't know if XAML apps can utilize WinMD files so a regular C# library guarantees that the code is reusable in both.

    This topic feels like its leaning more towards the C# forum.


    -Jeff

    Thursday, March 29, 2012 5:58 PM
  • I got you Jeff,

    Yes you have to ensure anything that is exposed is a WinRT type.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 29, 2012 6:25 PM
    Moderator
  • I'm just wondering if its a good idea, or terrible idea to do this.   It feels like a good idea to me but what do you think?


    -Jeff

    Thursday, March 29, 2012 6:39 PM
  • I think code re-use is a good thing whenever you can do it!

    Jeff Sanders (MSFT)

    Thursday, March 29, 2012 6:40 PM
    Moderator
  • Thanks for your help Jeff!

    -Jeff

    Thursday, March 29, 2012 6:43 PM