﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - Crosslight - Write my own MVVM based mobile services</title><link>http://www.intersoftsolutions.com/Community/Crosslight/Write-my-own-MVVM-based-mobile-services/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>Write my own MVVM based mobile services</title><link>http://www.intersoftsolutions.com/Community/Crosslight/Write-my-own-MVVM-based-mobile-services/</link><pubDate>Wed, 13 Aug 2014 05:28:06 GMT</pubDate><dc:creator>yudi</dc:creator><category>MVVM</category><category>Mobile Services</category><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;I started to create a simple sample by using &lt;em&gt;Blank&lt;/em&gt; project template.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Next, I added an interface called ICustomService which inherits IMobileComponentService. The snippet code below shows how the interface is declared in &lt;strong&gt;ICustomService.cs&lt;/strong&gt; file in the &lt;strong&gt;Core&lt;/strong&gt; project.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;using Intersoft.Crosslight.Mobile;

namespace CustomService.Core.Custom
{
    public interface ICustomService : IMobileComponentService
    {
        void DoSomething();
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;In the &lt;strong&gt;SimpleViewModel&lt;/strong&gt; class, &lt;strong&gt;ShowToast&lt;/strong&gt; function is modified by resolving CustomService via IoC (injection of Container) technique. If &lt;em&gt;customService is not null&lt;/em&gt;, invokes &lt;em&gt;DoSomething()&lt;/em&gt; method.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;private void ShowToast(object parameter)
{
    //this.ToastPresenter.Show("You entered: " + this.NewText);
    //this.GreetingText = this.NewText;

    ICustomService customService = ServiceProvider.GetService&amp;lt;ICustomService&amp;gt;(); //resolve CustomService via IoC (injection of Container)
    if (customService != null)
    {
        customService.SetOwner(this); //needed for Android platform only
        customService.DoSomething();
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Next, we need to register the custom service in the AppInitializer class, specifically in the InitializeServices method.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;public void InitializeServices(IApplicationHost appHost)
{
    ServiceProvider.AddService&amp;lt;ICustomService, CustomiOSService&amp;gt;();
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Please note that we need to repeat this step for each platform (Android, iOS, Windows Phone, and Windows StoreApp).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Last, implement &lt;strong&gt;DoSomething&lt;/strong&gt; method for each platform. In the sample, what DoSomething doing is very easy, it shows "Custom Service" alert.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;using CustomService.Core.Custom;
using Intersoft.Crosslight.iOS;
using MonoTouch.UIKit;

namespace CustomService.iOS.Custom
{
    public class CustomiOSService : IOSMobileComponentServiceBase, ICustomService
    {
        public void DoSomething()
        {
            UIAlertView alert = new UIAlertView("Custom service", "Custom Service", null, "OK", null);
            alert.Show();
        }
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;The sample can be downloaded in &lt;a href="https://onedrive.live.com/download?resid=A29317908CEA783A%21408" target="_blank"&gt;https://onedrive.live.com/download?resid=A29317908CEA783A%21408&lt;/a&gt;. Please let us know whether this help or not.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Write my own MVVM based mobile services</title><link>http://www.intersoftsolutions.com/Community/Crosslight/Write-my-own-MVVM-based-mobile-services/</link><pubDate>Wed, 13 Aug 2014 02:37:47 GMT</pubDate><dc:creator>hongliyu2002</dc:creator><category>MVVM</category><category>Mobile Services</category><description>&lt;p&gt;Most of third party mobile cloud platforms provide lots of powerful services, such as Storage, Push Notification, Audio/Video Encoding, LBS, Social Share, Analysis, Feed Back etc.. &amp;nbsp;As you know, they usually provide iOS &amp;amp; Android SDKs, sometimes javascript SDK.&amp;nbsp;&lt;span style="font-size: 10pt;"&gt;My question is&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;How can we write our C# code to wrap these iOS/Android class libraries, and integrate with Crosslight MVVM pattern, such as write our own Mobile Service (only invoked in ViewModel layer), just like Crosslight mobile service did? &amp;nbsp;Can you give us any ideas or samples?&lt;/span&gt;&lt;/p&gt;</description></item></channel></rss>