Convert ObjectStore ext class to implement IObjectStore for API

Since extension methods don't play well with pythonnet, this change converts
the extensions class into a decorator class. Additionally, this ObjectStore
type is the type that gets exposed via QCAlgorithm so users can access these
methods directly without requiring the use of extension methods.

This approach has many good properties. For one, it doesn't force implementors
of IObjectStore to use a base class. Second, it maintains healthy separation of
API level concerns (such as convenient methods) from the  abstraction level conerns
of IObjectStore. Setting it up in this way ensures ANY implementation of IObjectStore
will still get access to these additional methods. Another thing to note is this
prevents using a base class on QCAlgorithm's public interface. Instead, we have a
specific type that is dedicated to fulfilling API level requirements, which also
provides us flexibility in the event the API needs to be updated. If it were a subclass,
you run the risk of breaking the implementors of the subclass.
This commit is contained in:
Michael Handschuh
2019-12-31 15:32:31 -05:00
parent 7d9c67364b
commit 39935552a3
6 changed files with 143 additions and 36 deletions
@@ -33,6 +33,7 @@ using QuantConnect.Securities.Option;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using QuantConnect.Storage;
namespace QuantConnect.AlgorithmFactory.Python.Wrappers
{
@@ -287,7 +288,7 @@ namespace QuantConnect.AlgorithmFactory.Python.Wrappers
/// <summary>
/// Gets the object store, used for persistence
/// </summary>
public IObjectStore ObjectStore => _baseAlgorithm.ObjectStore;
public ObjectStore ObjectStore => _baseAlgorithm.ObjectStore;
/// <summary>
/// Returns the current Slice object