예제 #1
0
        public AppUserModelService(IUserApiService userApiService, ILogger logger, IAppSettings appSettings)
        {
            _favouriteCakes = new SourceCache <CakeDto, int>(c => c.Id);
            _appSettings    = appSettings;
            _userIdSubject  = new BehaviorSubject <string>(String.Empty);
            _userSubject    = new BehaviorSubject <UserDto>(null);
            _cd             = new CompositeDisposable();

            _favouriteCakes
            .Connect()
            .CacheChangeSet(CacheKey, logger)
            .Subscribe();

            _userIdSubject
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Where(u => u != null)
            .SelectMany(async uId => await userApiService.GetFavourites(uId))
            .RetryWithBackoff(3)
            .LogException(logger)
            .Subscribe(cakes =>
            {
                _favouriteCakes.Edit(l => l.AddOrUpdate(cakes));
            })
            .DisposeWith(_cd);

            Observable.FromAsync(async() => await _favouriteCakes.FromCache(CacheKey, EqualityComparer <CakeDto> .Default)).Subscribe().DisposeWith(_cd);
        }