Replicator best practices

Good morning. I am developing in Xamarin and I wanted to ask about best practices for the replicator. Do I put that code maybe in the App.xaml.cs file for it to be live while the whole application is open? Or do I close it when a exiting a screen and call it again when opening another screen?

I hope this makes sense.

Thank you,

Brian

Hi Brian,

I made a project in xamarin forms with couchbase, meaby I will be able to help you.

Here is what I have in my common app.xaml.cs file :

public partial class App : Application
{
private readonly Startup _startup=null;
private static readonly SimpleInjector.Container _container = new SimpleInjector.Container();

  public static Container Injector => _container;

  public  App ()
  {
  	InitializeComponent();

  	var userSelectedCulture = new CultureInfo("fr-FR");

  	Thread.CurrentThread.CurrentCulture = userSelectedCulture;

  	if (_startup == null)
  	{
  		_startup = new Startup();
  		_startup.ConfigureServices(_container);
  	}

  	AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

  	MainPage = _container.GetInstance<mobiLotis.MainPage>();
  }

  private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  {
  	Injector.GetInstance<ISynchroExDal>().Save(e.ExceptionObject as Exception);
  }

  protected override void OnStart ()
  {
  	if (CrossConnectivity.IsSupported)
  		CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;
  }

  private void Current_ConnectivityChanged(object sender, Plugin.Connectivity.Abstractions.ConnectivityChangedEventArgs e)
  {
  	MessagingCenter.Send(new ConnectivityMessage(e.IsConnected), "CONNECTIVITY_STATUS");
  }

  protected override void OnSleep ()
  {
  	if (CrossConnectivity.IsSupported)
  		CrossConnectivity.Current.ConnectivityChanged -= Current_ConnectivityChanged;
  }

  protected override void OnResume ()
  {
  	if (CrossConnectivity.IsSupported)
  		CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;
  }

Don’t forget, in each project you will have to activate couchbase lite, here is the UWP example :

public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
Couchbase.Lite.Support.UWP.Activate();

  	LoadApplication(new mobiLotis.App());
    }
}

The android Example :

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);
  	
  	global::Xamarin.Forms.Forms.Init(this, bundle);

  	Couchbase.Lite.Support.Droid.Activate(this);
  	App app = new App();

  	try
  	{
  		LoadApplication(app);
  	}
  	catch(Exception)
  	{
  		Debugger.Break();
  	}
    }
}

I don’t know if this will be the answer you’re looking for.

Steeve