Orchard icon indicating copy to clipboard operation
Orchard copied to clipboard

Content handler call order

Open ViRuSTriNiTy opened this issue 7 years ago • 5 comments

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

ViRuSTriNiTy avatar Sep 07 '16 07:09 ViRuSTriNiTy

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 avatar Sep 07 '16 09:09 carlwoodhouse

@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.

sebastienros avatar Sep 08 '16 19:09 sebastienros

Side note: a solution has been posted here: http://stackoverflow.com/a/39367226/3936440

ViRuSTriNiTy avatar Dec 01 '16 11:12 ViRuSTriNiTy

Is there any update on this?

robmuk0 avatar Jan 14 '22 21:01 robmuk0

afaik, things still stand as they did and as they were described in the comments above.

MatteoPiovanelli-Laser avatar Jan 15 '22 00:01 MatteoPiovanelli-Laser