diff --git a/Effort.Extra.EF6.StrongName/Effort.Extra.EF6.StrongName.csproj b/Effort.Extra.EF6.StrongName/Effort.Extra.EF6.StrongName.csproj
index 619050d..bf56392 100644
--- a/Effort.Extra.EF6.StrongName/Effort.Extra.EF6.StrongName.csproj
+++ b/Effort.Extra.EF6.StrongName/Effort.Extra.EF6.StrongName.csproj
@@ -152,9 +152,6 @@
ObjectData.cs
-
- ObjectDataCollection.cs
-
ObjectDataLoader.cs
diff --git a/Effort.Extra.EF6.Tests/Effort.Extra.EF6.Tests.csproj b/Effort.Extra.EF6.Tests/Effort.Extra.EF6.Tests.csproj
index 555ec86..f0d27bf 100644
--- a/Effort.Extra.EF6.Tests/Effort.Extra.EF6.Tests.csproj
+++ b/Effort.Extra.EF6.Tests/Effort.Extra.EF6.Tests.csproj
@@ -132,9 +132,6 @@
ObjectData.cs
-
- ObjectDataCollection.cs
-
ObjectDataLoader.cs
diff --git a/Effort.Extra.EF6/Effort.Extra.EF6.csproj b/Effort.Extra.EF6/Effort.Extra.EF6.csproj
index 36cfcb1..14746c0 100644
--- a/Effort.Extra.EF6/Effort.Extra.EF6.csproj
+++ b/Effort.Extra.EF6/Effort.Extra.EF6.csproj
@@ -146,9 +146,6 @@
ObjectData.cs
-
- ObjectDataCollection.cs
-
ObjectDataLoader.cs
diff --git a/Effort.Extra.StrongName/Effort.Extra.StrongName.csproj b/Effort.Extra.StrongName/Effort.Extra.StrongName.csproj
index 1eda4a1..c6c0ef8 100644
--- a/Effort.Extra.StrongName/Effort.Extra.StrongName.csproj
+++ b/Effort.Extra.StrongName/Effort.Extra.StrongName.csproj
@@ -147,9 +147,6 @@
ObjectData.cs
-
- ObjectDataCollection.cs
-
ObjectDataLoader.cs
diff --git a/Effort.Extra.Tests/Effort.Extra.Tests.csproj b/Effort.Extra.Tests/Effort.Extra.Tests.csproj
index 3383f76..687215c 100644
--- a/Effort.Extra.Tests/Effort.Extra.Tests.csproj
+++ b/Effort.Extra.Tests/Effort.Extra.Tests.csproj
@@ -163,7 +163,6 @@
-
diff --git a/Effort.Extra.Tests/ObjectDataCollection.cs b/Effort.Extra.Tests/ObjectDataCollection.cs
deleted file mode 100644
index a0134d8..0000000
--- a/Effort.Extra.Tests/ObjectDataCollection.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-
-namespace Effort.Extra.Tests
-{
- using System;
- using Machine.Fakes;
- using Machine.Specifications;
-
- internal class ObjectDataCollection
- {
- public class GetKeyForItem
- {
- [Subject("ObjectDataCollection.GetKeyForItem")]
- public abstract class get_key_for_item : WithSubject
- {
- protected static Exception thrown_exception;
- protected static Extra.ObjectData item;
- protected static Guid result;
-
- Because of = () => thrown_exception = Catch.Exception(
- () => result = Subject.GetKeyForItem(item));
- }
-
- public class when_item_is_null : get_key_for_item
- {
- Establish context = () =>
- {
- item = null;
- };
-
- It throws_an_argument_null_exception =
- () => thrown_exception.ShouldBeOfExactType();
- }
-
- public class when_item_is_valid : get_key_for_item
- {
- Establish context = () =>
- {
- item = new Extra.ObjectData();
- };
-
- It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();
-
- It the_result_is_the_correct_value = () => result.ShouldEqual(item.Identifier);
- }
- }
-
- public class AddOrUpdate
- {
- [Subject("ObjectDataCollection.AddOrUpdate")]
- public abstract class add_or_update_context : WithSubject
- {
- protected static Exception thrown_exception;
- protected static Extra.ObjectData data;
-
- Because of = () => thrown_exception = Catch.Exception(() => Subject.AddOrUpdate(data));
- }
-
- public class when_data_is_not_already_in_the_collection : add_or_update_context
- {
- Establish context = () =>
- {
- data = new Extra.ObjectData();
- };
-
- It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();
-
- It the_data_is_added_to_the_collection = () => Subject.Contains(data);
- }
-
- public class when_data_is_already_in_the_collection : add_or_update_context
- {
- static Extra.ObjectData existing;
-
- Establish context = () =>
- {
- var guid = Guid.NewGuid();
- existing = new StubObjectData(guid);
- Subject.Add(existing);
- data = new StubObjectData(guid);
- };
-
- It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();
-
- It the_data_is_added_to_the_collection = () => Subject.Contains(data);
-
- It the_existing_item_is_not_longer_in_the_collection =
- () => Subject[existing.Identifier].ShouldNotBeTheSameAs(existing);
- }
-
- public class StubObjectData : Extra.ObjectData
- {
- private readonly Guid identifier;
-
- public StubObjectData(Guid identifier)
- {
- this.identifier = identifier;
- }
-
- internal override Guid Identifier { get { return identifier; } }
- }
- }
-
- public class TryGetValue
- {
- [Subject("ObjectDataCollection.TryGetValue")]
- public abstract class try_get_value_context : WithSubject
- {
- protected static Exception thrown_exception;
- protected static Guid key;
- protected static Extra.ObjectData data;
- protected static bool result;
-
- Because of = () => thrown_exception = Catch.Exception(
- () => result = Subject.TryGetValue(key, out data));
- }
-
- public class when_key_does_not_exist : try_get_value_context
- {
- Establish context = () =>
- {
- key = Guid.NewGuid();
- };
-
- It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();
-
- It the_data_should_be_null = () => data.ShouldBeNull();
-
- It the_result_is_false = () => result.ShouldBeFalse();
- }
-
- public class when_key_exists : try_get_value_context
- {
- Establish context = () =>
- {
- var item = new Extra.ObjectData();
- Subject.Add(item);
- key = item.Identifier;
- };
-
- It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();
-
- It the_data_should_not_be_null = () => data.ShouldNotBeNull();
-
- It the_result_is_true = () => result.ShouldBeTrue();
- }
- }
-
- public class StubObjectDataCollection : Extra.ObjectDataCollection
- {
- public new Guid GetKeyForItem(Extra.ObjectData item)
- {
- return base.GetKeyForItem(item);
- }
- }
- }
-}
diff --git a/Effort.Extra/Effort.Extra.csproj b/Effort.Extra/Effort.Extra.csproj
index 87432ee..4f208f8 100644
--- a/Effort.Extra/Effort.Extra.csproj
+++ b/Effort.Extra/Effort.Extra.csproj
@@ -142,7 +142,6 @@
Properties\SharedAssemblyInfo.cs
-
diff --git a/Effort.Extra/ObjectDataCollection.cs b/Effort.Extra/ObjectDataCollection.cs
deleted file mode 100644
index 0bf33ab..0000000
--- a/Effort.Extra/ObjectDataCollection.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-
-namespace Effort.Extra
-{
- using System;
- using System.Collections.ObjectModel;
-
- ///
- /// A keyed collection for ObjectData
- ///
- internal class ObjectDataCollection : KeyedCollection
- {
- private readonly object locker = new object();
-
- ///
- /// Extracts the key from the specified element.
- ///
- /// The element from which to extract the key.
- ///
- /// The key for the specified element.
- ///
- protected override Guid GetKeyForItem(ObjectData item)
- {
- if (item == null) throw new ArgumentNullException(nameof(item));
- return item.Identifier;
- }
-
- ///
- /// If the data already exists in the collection then it is updated, otherwise it is added.
- ///
- /// The data.
- public void AddOrUpdate(ObjectData data)
- {
- lock (locker)
- {
- if (data == null) throw new ArgumentNullException(nameof(data));
- if (Contains(data.Identifier)) Remove(data.Identifier);
- Add(data);
- }
- }
-
- ///
- /// Tries to get the value.
- ///
- /// The key.
- /// The data.
- /// true, if the key exists, otherwise false.
- public bool TryGetValue(Guid key, out ObjectData data)
- {
- lock (locker)
- {
- data = Contains(key) ? this[key] : null;
- return data != null;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Effort.Extra/ObjectDataLoader.cs b/Effort.Extra/ObjectDataLoader.cs
index 7986e7c..a3c4be6 100644
--- a/Effort.Extra/ObjectDataLoader.cs
+++ b/Effort.Extra/ObjectDataLoader.cs
@@ -2,6 +2,7 @@
namespace Effort.Extra
{
using System;
+ using System.Collections.Concurrent;
using System.Collections.Generic;
using Effort.DataLoaders;
@@ -10,7 +11,7 @@ namespace Effort.Extra
///
public class ObjectDataLoader : IDataLoader
{
- private static readonly ObjectDataCollection DataCollection = new ObjectDataCollection();
+ private static readonly ConcurrentDictionary DataCollection = new ConcurrentDictionary();
///
/// Initializes a new instance of the class.
@@ -25,7 +26,7 @@ public ObjectDataLoader(ObjectData data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
Argument = data.Identifier.ToString();
- DataCollection.AddOrUpdate(data);
+ DataCollection.AddOrUpdate(data.Identifier, data, (key, value) => data);
}
///
@@ -50,11 +51,9 @@ public ObjectDataLoader(ObjectData data)
///
public ITableDataLoaderFactory CreateTableDataLoaderFactory()
{
- Guid id;
- if (Guid.TryParse(Argument, out id))
+ if (Guid.TryParse(Argument, out var id))
{
- ObjectData data;
- if (DataCollection.TryGetValue(id, out data))
+ if (DataCollection.TryGetValue(id, out var data))
{
return new ObjectDataLoaderFactory(data);
}