Reputation: 6378
I'm having some doubts about how to store a simple class like Person
in a Xml File.
According to my knowledgwe, I've got to create first the Xml service which contains functions like GetPersons()
and SavePersons(IEnumerable<Person> persons)
.
And my repository should contain something like the possible queries, Add
and Remove
also. I really want to someone explain how can I start to implement these two things? The idea main idea is store it in a xml file and to get some queries from the repository.
Upvotes: 2
Views: 608
Reputation: 39898
The idea behind the Repository pattern is that you hide the details of the data store. So a user of your repository would only see an interface with methods like:
public interface IPersonRepository
{
void Add(Person person);
void Remove(Person person);
void GetById(int personId);
}
If you want to use XML as your data store, you should create a XmlPersonRepository
that implements the IPersonRepository
interface. Inside those methods you could use the .NET classes to directly access the XML file or you could load your XML data into a DataSet
and access it in a more relational way.
What would you do if you had several repositories? One for persons, one for products and one for orders. If you then want a single transaction that spans these three repositories and saves the changes in one block, you would also need another pattern. The UnitOfWork.
Patterns of Enterprise Archicture defines a UnitOfWork as:
Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
Upvotes: 2