SimpleInjector IEnumerable<ISomeService<T>> with a mixture of open & closed generics – the problem

Please note that as of Release 2.3 of SimpleInjector the features discussed in this and related articles are available out of the box with the new registration method RegisterAllOpenGeneric I like SimpleInjector, it’s great and so is the support. The guy behind SimpleInjector is a top class craftsman. However I recently discovered that SimpleInjector does not return any open generic… Read more →

How to cancel Parallel.ForEach

static void Main(string[] args) { List<RandomWait> waiters = new List<RandomWait>(); for (int i = 0; i < 1000; i++) { waiters.Add(new RandomWait()); } int counter = 0; ParallelOptions options = new ParallelOptions(); CancellationTokenSource cancelToken = new CancellationTokenSource(); options.MaxDegreeOfParallelism = 15; options.CancellationToken = cancelToken.Token; Task.Factory.StartNew(() => { Parallel.ForEach(waiters, options, (waiter) => { counter++; Console.WriteLine(counter); waiter.Pause(); counter–; Console.WriteLine(counter); }); }); Console.ReadLine(); cancelToken.Cancel();… Read more →

Aspect Oriented Programming (AOP)

We have found many programming problems for which neither procedural nor object-oriented programming techniques are sufficient to clearly capture some of the important design decisions the program must implement. This forces the implementation of those design decisions to be scattered throughout the code, resulting in “tangled” code that is excessively difficult to develop and maintain. We present an analysis of why certain design… Read more →