• Mobile
  • Extensions
  • Releases
  • GitHub
  • Blog
  • Sponsor
Show / Hide Table of Contents
  • Home
  • Quick Start
  • Setup
    • Dependency Injection
    • Startup
    • Static Instances
    • iOS
    • Android
  • Configuration Extensions
  • Jobs
    • Getting Started
    • Frequently Asked Questions
  • Bluetooth LE Client
    • Scanning
    • Peripheral
    • Best Practices
    • Manged Scanning
    • Managed Peripheral
  • Bluetooth LE Hosting
    • Getting Started
    • GATT
    • Advertising
  • Locations
    • Geofencing
    • GPS
    • Motion Activity
  • Local Notifications
    • Getting Started
    • Channels
  • Push Notifications
    • Getting Started
    • Native
    • Azure Notification Hubs
    • Firebase Messaging
    • One Signal
  • Beacons
    • Ranging
    • Monitoring (Background)
  • HTTP Transfers
    • Getting Started
    • Advanced
  • Framework
    • Getting Started
    • ViewModel
  • Sensors
    • Getting Started
    • Accelerometer
    • Ambient Light
    • Barometer
    • Compass
    • Gyroscope
    • Humidity
    • Magnetometer
    • Pedometer
    • Proximity
    • Temperature

Dependency Injection

Startup Tasks

Startup tasks are great for wiring up events and spinning up infrastructure. These fire immediately after the container is built. However, don't do any sort of blocking operation in them as this will cause your app to pause starting up causing a poor user experience.

CAUTION: You can do async processes here, but your app could start before the process finishes, so if you are pre-loading data, it may not be ready for use before your app starts

using Shiny;

public class YourStartupTask : IShinyStartupTask
{
    // you can inject into the constructor here as long as you register the service in the startup
    public void Start()
    {

    }
}

To register them and have them automatically run:

<?! Startup ?> services.AddSingleton(); <?!/ Startup ?>

State Restorable Services

This is pretty cool, imagine you want the state of your service preserved across restarts - Shiny does this in epic fashion

Simply turn your service implement INotifyPropertyChanged (or the easy Shiny.NotifyPropertyChanged) and register it in your shiny startup and Shiny will take care of the rest

using Shiny;

public class MyBadAssService : NotifyPropertyChanged, IShinyStartupTask
{
    int count;

    public int Count
    {
        get => this.count;
        set => this.Set(ref this.count, value);
    }

    public void Start()
    {
        this.Count++;
    }
}

and the same to register this guy

<?! Startup ?> services.AddSingleton(); <?!/ Startup ?>

  • Improve this Doc
In This Article
Back to top Generated by DocFX