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.
Warning
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:
'''shinystartup
services.AddSingleton
and the same to register this guy
## 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
```cs
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++;
}
}
using Microsoft.Extensions.DependencyInjection;
using Shiny;
namespace YourNamespace
{
public class YourShinyStartup : ShinyStartup
{
public override void ConfigureServices(IServiceCollection services, IPlatform platform)
{
services.AddSingleton