Skip to content

XmlRepository Documentation

Omar Piani edited this page Aug 27, 2019 · 7 revisions

This implementation is a prerelease, please leave feedbacks in Issues in order to mark as stable

This implementation persist data in Xml files using the library System.Xml.Serialization included in .NET Framework and .NET Core 2 so it doesn't install any addictional nuget package.

Install

Install-Package SharpRepository.XmlRepository

Configuration

Installing this repository you will have a sample json configuration file called repository.xml.json

{
  "sharpRepository": {
    "repositories": {
      "default": "xml",
      "xml": {
        "factory": "SharpRepository.XmlRepository.XmlConfigRepositoryFactory, SharpRepository.XmlRepository",
        "directory": "xmlDestinationDirectory"
      }
    }
  }
}

Other SharpRepository configuration options are in repository.sample.json

By default, if you have a .NET Core application you have to add "sharpRepository" section to your application.json. If you have .NET Framework, by default, you have to create a repository.json file

The only option to configure is directory where to save xmls, remember that XmlRepository does not create folder, you have to create it

Working with XmlRepository

As all serializer you will encounter some issues with models. You can find some tricks here

Common practices are:

  • Remove or add [XmlIgnore] to inverse navigation properties
  • Use List<> or array instead of instances (IEnumerable, ICollection) in "many" relationships

Clone this wiki locally