Hi all,
Firstly.... sorry for the length of this. Please keep reading.
I'm looking for some advice on how best to refactor a project that I am building in order to maintain the projects simplicity.
I'm building a blogging engine.... partly as a learning exercise and partly as all the open source solutions I've found are either feature incomplete or have been cobbled together out of code of varying (sometimes pretty poor) quality. The idea is that I can then give something back to the community.
I've started by building my data access layer using the repository pattern whilst utilizing generics to allow me to more easily add features to the engine.
On top of that I've defined a blog provider interface from which I can define custom providers to allow flexibliy of persistance methods (I'm defaulting with XML storage). These would then be called by a static service class which determines which provider to use based on a value in my web.config
The problem I am now having is with the complexity of these providers. Whilst the basic CRUD features are simple and interchangeable I've been
writing type specific methods to instruct my generic persistance classes.
This would be fine if I only had one or two types to persist but now I'm looking at host, blog, blogsettings, post, category, tag with more to follow.
This means that for every type I'm adding that's 4 maybe 5 methods to add to my provider interface, then to my abstract provider base class then to my providers. Then i have to add the methods to call the provider methods to my service class. It's all starting to get a bit silly.
My first thoughts would be to change my methods in my service class to accept a type parameter so rather than:
Blog SelectBlog (Guid id){
provider.selectBlog(id);
}
and
Post SelectPost (Guid id){
provider.selectPost(id);
}
I would instead use something like:
IEntity SelectObject (Type type, Guid id){
}
With another method in my class that would enumerate through known types in my project and choose the correct persistance method to call.
Whadya reckon?
Thanks for reading!
James