public static void ConfigureCortexServices(IServiceCollection services) { services.AddCortexService <AppStore>(s => { var sharedState = s.GetRequiredService <ISharedState>(); var appStore = sharedState.Observable(() => new AppStore { }); appStore.OnCreate(); return(appStore); }); services.AddCortexService <TodoPageStore>(s => { var todoService = s.GetRequiredService <ITodoService>(); var sharedState = s.GetRequiredService <ISharedState>(); var stateFactory = s.GetRequiredService <IStateFactory>(); var commander = s.GetRequiredService <ICommander>(); var session = s.GetRequiredService <Stl.Fusion.Authentication.Session>(); return(sharedState.Observable(() => { var s = new TodoPageStore(sharedState, stateFactory, session, todoService, commander); return s; })); }); }
public static void ConfigureCortexServices(IServiceCollection services) { // https://jspuij.github.io/Cortex.Net.Docs/pages/sharedstate.html services.AddCortexService <ISharedState>(sp => { // create an instance using the configuration var sharedState = new SharedState(new CortexConfiguration() { // enforce that state mutation always happens inside an action. EnforceActions = EnforceAction.Always, AutoscheduleActions = true, SynchronizationContext = SynchronizationContext.Current, }); // spy event handler should be in the object itself to prevent mem-leak as there is no dispose //sharedState.SpyEvent += SharedState_SpyEvent; return(sharedState); }); services.AddCortexService <AppStore>(s => { var sharedState = s.GetRequiredService <ISharedState>(); var appStore = sharedState.Observable(() => new AppStore { }); appStore.OnCreate(); return(appStore); }); services.AddCortexService <TodoPageStore>(s => { var todoService = s.GetRequiredService <ITodoService>(); var sharedState = s.GetRequiredService <ISharedState>(); var stateFactory = s.GetRequiredService <IStateFactory>(); var commander = s.GetRequiredService <ICommander>(); var session = s.GetRequiredService <Stl.Fusion.Authentication.Session>(); return(sharedState.Observable(() => { var s = new TodoPageStore(stateFactory, session, todoService, commander); return s; })); }); }