Skip to content
This repository was archived by the owner on Dec 13, 2021. It is now read-only.

Commit 28535eb

Browse files
authored
Merge pull request #242 from umco/develop
Preparing Ditto 0.12.2 release
2 parents 59faa63 + b993561 commit 28535eb

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image: Visual Studio 2017
22

33
# version format
4-
version: 0.12.1.{build}
4+
version: 0.12.2.{build}
55

66
# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
77
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta
@@ -48,7 +48,7 @@ deploy:
4848
- provider: NuGet
4949
server:
5050
api_key:
51-
secure: 0+oAleUTnr9UuJrhLW5rphRR+QGz00XX1Ui3k5kwyr2kUdEamiQ3F+gW0q8MJbDT
51+
secure: vEophXSqus5F60LRBY4/j1l6K/S5+n3/yYpiID3O7JJW1gyj+0q0enuHhN3tgdhl
5252
artifact: /.*\.nupkg/
5353
on:
5454
branch: master

src/Our.Umbraco.Ditto/ComponentModel/Attributes/DittoProcessorAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected DittoProcessorAttribute()
2121
{
2222
if (Ditto.TryGetTypeAttribute(this.GetType(), out DittoProcessorMetaDataAttribute metaData, true) == false || metaData == null)
2323
{
24-
throw new ApplicationException("Ditto processor attributes require a DittoProcessorMetaData attribute to be applied to the class but none was found.");
24+
throw new ApplicationException($"The Ditto processor attribute ('{this.GetType()}') requires a DittoProcessorMetaData attribute to be applied to the class but none was found.");
2525
}
2626

2727
this.ValueType = metaData.ValueType;

src/Our.Umbraco.Ditto/ComponentModel/ObjectResolution/AttributedTypeResolver.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ namespace Our.Umbraco.Ditto
1212
/// <typeparam name="TAttribute">A specific Ditto attribute type.</typeparam>
1313
internal sealed class AttributedTypeResolver<TAttribute> where TAttribute : Attribute
1414
{
15-
private readonly ConcurrentDictionary<Type, TAttribute> _attributedTypeLookup;
15+
private readonly object _lock = new object();
16+
17+
private readonly Dictionary<Type, TAttribute> _attributedTypeLookup;
1618

1719
private AttributedTypeResolver()
1820
{
19-
_attributedTypeLookup = new ConcurrentDictionary<Type, TAttribute>();
21+
_attributedTypeLookup = new Dictionary<Type, TAttribute>();
2022
}
2123

2224
private void Initialize(IEnumerable<Type> types, bool inherit = false)
2325
{
24-
if (types != null)
26+
// NOTE: Lock when initializing the resolver, so that it can't be read from (at the same time).
27+
lock (_lock)
2528
{
26-
foreach (var type in types)
29+
if (types != null)
2730
{
28-
TryAddAttributedType(type, out TAttribute attribute, inherit);
31+
foreach (var type in types)
32+
{
33+
TryAddAttributedType(type, out TAttribute attribute, inherit);
34+
}
2935
}
3036
}
3137
}
@@ -83,7 +89,8 @@ private bool TryAddAttributedType(Type type, out TAttribute attribute, bool inhe
8389
{
8490
if (_attributedTypeLookup.ContainsKey(type) == false)
8591
{
86-
return _attributedTypeLookup.TryAdd(type, attribute);
92+
_attributedTypeLookup.Add(type, attribute);
93+
return true;
8794
}
8895
else
8996
{
@@ -103,14 +110,18 @@ private bool TryAddAttributedType(Type type, out TAttribute attribute, bool inhe
103110
/// <returns>Returns the associated attribute for the given object-type.</returns>
104111
public bool TryGetTypeAttribute(Type type, out TAttribute attribute, bool inherit = false)
105112
{
106-
bool result = _attributedTypeLookup.TryGetValue(type, out attribute);
107-
108-
if (result == false)
113+
// NOTE: Lock when looking up from the resolver, to avoid concurrency issues.
114+
lock (_lock)
109115
{
110-
result = TryAddAttributedType(type, out attribute, inherit);
111-
}
116+
bool result = _attributedTypeLookup.TryGetValue(type, out attribute);
112117

113-
return result;
118+
if (result == false)
119+
{
120+
result = TryAddAttributedType(type, out attribute, inherit);
121+
}
122+
123+
return result;
124+
}
114125
}
115126
}
116127
}

0 commit comments

Comments
 (0)