///<summary>
        /// Sets custom mappings for this XmlRepository instance.
        ///</summary>
        ///<param name="propertyMappings">The property mappings to use.</param>
        ///<returns>The repository modifier for further modification.</returns>
        public IRepositoryModifier <TEntity, TIdentity> WithMappings(IDictionary <Type, IList <IPropertyMapping> > propertyMappings)
        {
            XmlRepository.AddDefaultPropertyMappingsFor(typeof(TEntity), propertyMappings);

            this.PropertyMappings = propertyMappings;
            return(this);
        }
Esempio n. 2
0
        internal static void AddRepositoryKey <TEntity, TIdentity>(XmlRepository <TEntity, TIdentity> repository) where TEntity : class, new()
        {
            var newKey = GetRepositoryKeyFromInstance(repository);

            repository.Key = newKey;

            Repositories.Add(newKey, repository);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets an xml repository for the specified entity type. If the repository has not been
        /// created yet, a new one is created; otherwise, the existing one is returned.
        /// e.g. RepositoryFor{Test}.WithIdentity(p => p.Name) for a entity named 'Test' and a identity property named 'Name' which is typed as string.
        /// </summary>
        /// <typeparam name="TEntity">The entity type.</typeparam>
        /// <typeparam name="TIdentity">The identity type.</typeparam>
        /// <param name="repositoryModifier">The selector for entity type and identity type.</param>
        /// <returns>An xml repository.</returns>
        public static IXmlRepository <TEntity, TIdentity> Get <TEntity, TIdentity>(IRepositoryModifier <TEntity, TIdentity> repositoryModifier) where TEntity : class, new()
        {
            lock (LockObject)
            {
                var key = new RepositoryKey
                {
                    RepositoryType   = typeof(IXmlRepository <TEntity, TIdentity>),
                    DataProvider     = repositoryModifier.DataProvider ?? DataProvider,
                    PropertyMappings = repositoryModifier.PropertyMappings ?? PropertyMappings,
                    QueryProperty    = repositoryModifier.QueryProperty
                };

                IXmlRepository <TEntity, TIdentity> repository;

                if (!Repositories.ContainsKey(key))
                {
                    repository     = new XmlRepository <TEntity, TIdentity>(repositoryModifier);
                    repository.Key = key;

                    Repositories.Add(key, repository);

                    // Add default mappings.
                    if (repositoryModifier.PropertyMappings != null)
                    {
                        AddDefaultPropertyMappingsFor(typeof(TEntity), repositoryModifier.PropertyMappings);
                    }
                    {
                        AddDefaultPropertyMappingsFor(typeof(TEntity));
                    }
                }
                else
                {
                    repository = Repositories[key] as IXmlRepository <TEntity, TIdentity>;
                }

                // Return the requested repository to the caller.
                return(repository);
            }
        }
Esempio n. 4
0
 private static RepositoryKey GetRepositoryKeyFromInstance <TEntity, TIdentity>(XmlRepository <TEntity, TIdentity> repository) where TEntity : class, new()
 {
     return(new RepositoryKey
     {
         RepositoryType = repository.GetType(),
         DataProvider = repository.DataProvider ?? DataProvider,
         PropertyMappings = repository.PropertyMappings ?? PropertyMappings,
         QueryProperty = repository.DefaultQueryProperty
     });
 }
Esempio n. 5
0
 internal static void RemoveRepositoryKey <TEntity, TIdentity>(XmlRepository <TEntity, TIdentity> repository) where TEntity : class, new()
 {
     Repositories.Remove(repository.Key);
 }