Leoβs second tip is that you use a handler filter.
In my blog, I have this example on how to make a simple filter for handlers , which, as it turned out, is the result that leads to ordered instances of the task when they are resolved using ResolveAll<ITask> (or when IEnumerable<ITask> is introduced):
class TaskHandlersFilter : IHandlersFilter { readonly Dictionary<Type, int> sortOrder = new Dictionary<Type, int> { {typeof (PrepareSomething), 1}, {typeof (CarryItOut), 2}, {typeof (FinishTheJob), 3}, }; public bool HasOpinionAbout(Type service) { return service == typeof(ITask); } public IHandler[] SelectHandlers(Type service, IHandler[] handlers) {
I also have a more complex example that plays with the API used to indicate the order - in this case, I allow types to indicate their position relative to another type, for example like
[ExecutesBefore(typeof(ExecutePayment))] public class ValidateCreditCards : ITask { ... }
which may / may not be useful in your specific situation :)
source share