Orchard
Orchard copied to clipboard
Content handler call order
Content handlers resolved by Autofac are returned in an unpredicatable order. I need some content handlers to be invoked in a specific order.
Example:
Feature A Content handler A -> assigns / removes role X from a user content item
Feature B Content handler B -> evaluates assigned roles and when role X is found it and takes further actions
As you see, in my case it makes no sense to call handler B before A as role X must be updated in A before B can even execute further actions based on the role X assignment.
Currently Autofac resolves the handlers in an ordering as follows
..., A, B, ...
but the handlers are stored in the handler list in the following order
... B, A, ...
Then Orchard invokes the handlers like
Handlers.Invoke(handler => ..., Logger);
which obviously calls the handlers in the order
... B, A, ...
Is there anything i can do to ensure a specific order?
Here is a discussion in google groups about a similar issue:
https://groups.google.com/forum/#!topic/autofac/HE66utFpvkg
I thought they already resolved in an order that obeys feature dependency, i maybe wrong though. If not that would seem reasonable.
Eg. if Feature B has a dependency on Feature A, A's handlers should fire first.
@carlwoodhouse is correct, they follow the feature dependencies order. However if the two have the same set of dependencies or come from the same feature then there is no predefined order.
What we could do is like ASP.NET Core and have an optional IOrder interface to implement on some services to ignore the default dependency based ordering system. If no interface is provided, then a default value is assumed.
Side note: a solution has been posted here: http://stackoverflow.com/a/39367226/3936440
Is there any update on this?
afaik, things still stand as they did and as they were described in the comments above.