TextFileRepository/PersistenceContext needs reimplementation
wislon opened this issue · comments
It's currently not implemented using proper generics. We need a generic IRepository implementation that uses a factory or service locator to figure out the best implementation of storage for a given type.
It shouldn't be up to the object which needs its data persisted, to determine how it's persisted. So implementing a new repository should not look like
private readonly IPersistenceContext<T> _persistenceContext;
public TextFileRepository(Context context)
{
_context = context;
_persistenceContext = new TextFilePersistenceContext<T>(_context);
}
instead it should look something like
public TextFileRepository(Context context)
{
_context = context;
_persistenceContext = new FooLocator<T>(_context);
}
where FooLocator looks at T and figures out what best to use, and returns something IPersistenceContext-y.
Normally we'd do this with an IoC container, but we don't have one yet.
TextFileRepository is now just IRepository. Still need to implement a proper persistence context service locator tho.
Going to keep the TextFilePersistenceContext for now. Might refactor everything later once I've got a better data-to-persistence mapping implementation.