Adds Repository Resolver and backing config section implementation U4-988
Will need a bit of refactoring because of the way UnitOfWork is currently implemented.
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.Repositories
|
||||
{
|
||||
internal class RepositoryConfigurationSection : ConfigurationSection
|
||||
{
|
||||
[ConfigurationProperty("repositories", IsDefaultCollection = false)]
|
||||
[ConfigurationCollection(typeof(RepositoryCollection),
|
||||
AddItemName = "add",
|
||||
ClearItemsName = "clear",
|
||||
RemoveItemName = "remove")]
|
||||
public RepositoryCollection Repositories
|
||||
{
|
||||
get
|
||||
{
|
||||
return (RepositoryCollection)base["repositories"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class RepositoryCollection : ConfigurationElementCollection
|
||||
{
|
||||
public RepositoryCollection()
|
||||
{
|
||||
Console.WriteLine("RepositoryCollection Constructor");
|
||||
}
|
||||
|
||||
public RepositoryElement this[int index]
|
||||
{
|
||||
get { return (RepositoryElement)BaseGet(index); }
|
||||
set
|
||||
{
|
||||
if (BaseGet(index) != null)
|
||||
{
|
||||
BaseRemoveAt(index);
|
||||
}
|
||||
BaseAdd(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(RepositoryElement repositoryElement)
|
||||
{
|
||||
BaseAdd(repositoryElement);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
BaseClear();
|
||||
}
|
||||
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new RepositoryElement();
|
||||
}
|
||||
|
||||
protected override object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
return ((RepositoryElement)element).Name;
|
||||
}
|
||||
|
||||
public void Remove(RepositoryElement repositoryElement)
|
||||
{
|
||||
BaseRemove(repositoryElement.Name);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
BaseRemoveAt(index);
|
||||
}
|
||||
|
||||
public void Remove(string name)
|
||||
{
|
||||
BaseRemove(name);
|
||||
}
|
||||
}
|
||||
|
||||
internal class RepositoryElement : ConfigurationElement
|
||||
{
|
||||
private const string NameKey = "name";
|
||||
private const string ModelTypeKey = "modelType";
|
||||
private const string RepositoryTypeKey = "repositoryType";
|
||||
|
||||
public RepositoryElement() { }
|
||||
|
||||
public RepositoryElement(string name, string modelType, string repositoryType)
|
||||
{
|
||||
Name = name;
|
||||
ModelType = modelType;
|
||||
RepositoryType = repositoryType;
|
||||
}
|
||||
|
||||
[ConfigurationProperty(NameKey, IsRequired = true, IsKey = true)]
|
||||
public string Name
|
||||
{
|
||||
get { return (string)this[NameKey]; }
|
||||
|
||||
set { this[NameKey] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ModelTypeKey, IsRequired = true, IsKey = false)]
|
||||
public string ModelType
|
||||
{
|
||||
get { return (string)this[ModelTypeKey]; }
|
||||
|
||||
set { this[ModelTypeKey] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(RepositoryTypeKey, IsRequired = true, IsKey = false)]
|
||||
public string RepositoryType
|
||||
{
|
||||
get { return (string)this[RepositoryTypeKey]; }
|
||||
|
||||
set { this[RepositoryTypeKey] = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.Repositories
|
||||
{
|
||||
internal sealed class RepositoryMappingCollection : ConfigurationElementCollection
|
||||
{
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new RepositoryMappingElement();
|
||||
}
|
||||
|
||||
protected override object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
return ((RepositoryMappingElement)element).InterfaceShortTypeName;
|
||||
}
|
||||
|
||||
public override ConfigurationElementCollectionType CollectionType
|
||||
{
|
||||
get { return ConfigurationElementCollectionType.BasicMap; }
|
||||
}
|
||||
|
||||
protected override string ElementName
|
||||
{
|
||||
get { return RepositoryMappingConstants.ConfigurationElementName; }
|
||||
}
|
||||
|
||||
public RepositoryMappingElement this[int index]
|
||||
{
|
||||
get { return (RepositoryMappingElement)this.BaseGet(index); }
|
||||
set
|
||||
{
|
||||
if (this.BaseGet(index) != null)
|
||||
{
|
||||
this.BaseRemoveAt(index);
|
||||
}
|
||||
this.BaseAdd(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
public new RepositoryMappingElement this[string interfaceShortTypeName]
|
||||
{
|
||||
get { return (RepositoryMappingElement)this.BaseGet(interfaceShortTypeName); }
|
||||
}
|
||||
|
||||
public bool ContainsKey(string keyName)
|
||||
{
|
||||
bool result = false;
|
||||
object[] keys = this.BaseGetAllKeys();
|
||||
foreach (object key in keys)
|
||||
{
|
||||
if ((string)key == keyName)
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Umbraco.Core.Configuration.Repositories
|
||||
{
|
||||
internal static class RepositoryMappingConstants
|
||||
{
|
||||
internal const string CacheProviderFullTypeNameAttributeName = "cacheProviderFullTypeName";
|
||||
internal const string ConfigurationPropertyName = "repositoryMappings";
|
||||
internal const string ConfigurationElementName = "repositoryMapping";
|
||||
internal const string InterfaceShortTypeNameAttributeName = "interfaceShortTypeName";
|
||||
internal const string RepositoryFullTypeNameAttributeName = "repositoryFullTypeName";
|
||||
internal const string RepositoryMappingsConfigurationSectionName = "repositoryMappingsConfiguration";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.Repositories
|
||||
{
|
||||
internal sealed class RepositoryMappingElement : ConfigurationElement
|
||||
{
|
||||
[ConfigurationProperty(RepositoryMappingConstants.InterfaceShortTypeNameAttributeName,
|
||||
IsKey = true, IsRequired = true)]
|
||||
public string InterfaceShortTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[RepositoryMappingConstants.InterfaceShortTypeNameAttributeName];
|
||||
}
|
||||
set
|
||||
{
|
||||
this[RepositoryMappingConstants.InterfaceShortTypeNameAttributeName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(RepositoryMappingConstants.RepositoryFullTypeNameAttributeName,
|
||||
IsRequired = true)]
|
||||
public string RepositoryFullTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[RepositoryMappingConstants.RepositoryFullTypeNameAttributeName];
|
||||
}
|
||||
set
|
||||
{
|
||||
this[RepositoryMappingConstants.RepositoryFullTypeNameAttributeName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(RepositoryMappingConstants.CacheProviderFullTypeNameAttributeName,
|
||||
IsRequired = true)]
|
||||
public string CacheProviderFullTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[RepositoryMappingConstants.CacheProviderFullTypeNameAttributeName];
|
||||
}
|
||||
set
|
||||
{
|
||||
this[RepositoryMappingConstants.CacheProviderFullTypeNameAttributeName] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.Repositories
|
||||
{
|
||||
internal class RepositorySettings : ConfigurationSection
|
||||
{
|
||||
[ConfigurationProperty(RepositoryMappingConstants.ConfigurationPropertyName,
|
||||
IsDefaultCollection = true)]
|
||||
public RepositoryMappingCollection RepositoryMappings
|
||||
{
|
||||
get { return (RepositoryMappingCollection)base[RepositoryMappingConstants.ConfigurationPropertyName]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user