using System.Collections.Generic;
using System.Collections.Concurrent;
public string Foo { get; set; }
public override string ToString()
public interface IRepositoryReloader
public interface IRepositoryLoader<out T> : IRepositoryReloader
IEnumerable<T> LoadData();
public abstract class Test<TItem,TContainer> : IRepositoryLoader<TItem> where TContainer : class, IEnumerable<TItem>
protected TContainer Source;
public abstract IEnumerable<TItem> LoadData();
void IRepositoryReloader.ReloadData()
this.Source = (TContainer)Activator.CreateInstance(typeof(TContainer), new [] { LoadData() } );
public override string ToString()
"Type:{0} Count:{1} Elements: {{{2}}}",
string.Join(",", Source.Select( s => string.Format("'{0}'", s)))
public class ConcurrentDataContainer : Test<MyDto, ConcurrentBag<MyDto>>
public override IEnumerable<MyDto> LoadData()
yield return new MyDto { Foo = "Element1" };
yield return new MyDto { Foo = "Element2" };
public class SingleThreadedDataContainer : Test<MyDto, List<MyDto>>
public override IEnumerable<MyDto> LoadData()
yield return new MyDto { Foo = "Element1" };
yield return new MyDto { Foo = "Element2" };
public static void Main()
IRepositoryReloader test1 = new ConcurrentDataContainer();
Console.WriteLine(test1.ToString());
IRepositoryReloader test2 = new SingleThreadedDataContainer();
Console.WriteLine(test2.ToString());