I’ve created an app with CRUD functions on XML documents with repository pattern.
I have 4 models (4 xml files) with each a repository class.
Before it was just 4 xml documents that were read into a XDocument object in the constructor.
itemData = XDocument.Load(HttpContext.Current.Server.MapPath("~/App_Data/Items/item1.xml"));
Now I would like to make the xml file dynamic, so it can read unlimited xmls
So whats the best approach? Making a second constructor and passing in a parameter from the url? Something like this:
public ItemRepository()
{
}
public ItemRepository(string xml)
{
itemData = XDocument.Load(HttpContext.Current.Server.MapPath("~/App_Data/Items/" + xml + ".xml"));
....
}
Any other suggestions? Cos i get NullReferenceException with the Model with this.
Easiest workaround is to just out the code from the constructor into all the CRUD methods. Here a link for a little more info (and more issues :P) NullReferenceException while using XElement