Example #1
0
        public TradeService(ILogger logger, TradeGenerator tradeGenerator, ISchedulerProvider schedulerProvider)
        {
            _logger            = logger;
            _tradeGenerator    = tradeGenerator;
            _schedulerProvider = schedulerProvider;

            //emulate a trade service which asynchronously
            IConnectableObservable <IChangeSet <Trade, long> > tradesData = GenerateTradesAndMaintainCache().Publish();

            //call AsObservableCache() so the cache can be directly exposed
            All = tradesData.AsObservableCache();

            //create a derived cache
            Live = tradesData.Filter(trade => trade.Status == TradeStatus.Live).AsObservableCache();

            //log changes
            IDisposable loggerWriter = LogChanges();

            _cleanup = new CompositeDisposable(All, tradesData.Connect(), loggerWriter);
        }