So I have a program that visualizes data from files (csv,txt,etc.). These files are saved to database as individual tables. In my application I have DocumentExplorer
which is just a module with a list of available documents(files). You can open and close any document you want, and you can have multiple documents opened at the same time.
This program also uses MEF to separate modules and exposes API module for users to create plugins. What I'm working on is some kind of manager to manage all opened documents in current session. Basically I need something that will be responsible for closing, opening, switching documents. I have 2 ideas how to deal with it, but I'm not sure whether they are any good or not. This is what I came up with so far:
1. DocumentManager
passed by IoC
container with interface exposed inside API module.
public class DocumentManager : IDocumentManager
{
private List<IDocument> ActiveDocuments { get; set; }
public void Create(IDocument document)
{
if(!ActiveDocuments.Contains(document))
ActiveDocuments.Add(document);
}
public void Close(IDocument document)
{
if (ActiveDocuments.Contains(document))
ActiveDocuments.Remove(document);
}
public IDocument Get(Expression<Func<IDocument, bool>> predicate)
{
return ActiveDocuments.AsQueryable().FirstOrDefault(predicate);
}
}
2. DocumentManager
as static class kept inside API module, so others can access it. (without IDocumentManager
interface, obviously)
What are your thoughts? Are these good approaches? Do you know any good tricks with this kind of problem?