public ClientState(AuthStateProvider authStateProvider, IStateFactory stateFactory)
        {
            AuthStateProvider = authStateProvider;
            SessionResolver   = AuthStateProvider.SessionResolver;

            User = stateFactory.NewLive <User>(
                o => o.WithUpdateDelayer(0, 1),
                async(_, cancellationToken) => {
                var authState = await AuthState.UseAsync(cancellationToken).ConfigureAwait(false);
                return(authState.User);
            });
        }
示例#2
0
        public ClientState(
            IChatService chatService,
            AuthStateProvider authStateProvider,
            IStateFactory stateFactory)
        {
            ChatService       = chatService;
            AuthStateProvider = authStateProvider;
            SessionResolver   = AuthStateProvider.SessionResolver;

            User = stateFactory.NewLive <User>(
                o => o.WithInstantUpdates(),
                async(_, cancellationToken) => {
                var authState = await AuthState.UseAsync(cancellationToken);
                return(authState.User);
            });
            ChatUser = stateFactory.NewLive <ChatUser?>(
                o => {
                o.InitialOutputFactory = _ => null;     // The default factory uses parameterless constructor instead
                o.WithInstantUpdates();
            },
                (_, cancellationToken) => ChatService.GetCurrentUserAsync(Session, cancellationToken));
        }