Bypassing Autofac for mods to Orchard

Topics: General, Troubleshooting
Jun 28, 2011 at 6:05 AM

It seems i've run into a brick wall with Autofac and AsyncControllers.  Is there anyway to bypass Autofac, or just remove it all together from the project without compromising it too much?

Hopefully I'll hear something eventually from the Autofac team over at http://stackoverflow.com/questions/tagged/autofac

Jun 28, 2011 at 9:38 AM

Without Autofac, nothing will work; literally nothing.

Jun 28, 2011 at 10:15 AM

What exactly is the problem? For both threads, this one and the one on stackoverflow, I can't understand what your issue is?

How would Autofac, an IoC container responsible for instantiating a class, or a resource if you will, have any type of interference with routing between actions?

Jun 29, 2011 at 3:09 AM
Edited Jun 29, 2011 at 3:10 AM

@sharpoverride:  I'm trying to track down a problem where I cannot get an AsyncController to work. 

Here's the deal.  If I create an AsyncController in a regular MVC3 application, It works fine.  The route, everything. 
AsyncControllers are like a 2 part regular controller.  You have the first part, and then the complete part (In my case IndexAsync and IndexCompleted.  When I route to 'Index' on my chat controller in my MVC3 Application, it processes my IndexAsync, then my other code, then finally, it finishes with IndexCompleted, It routes just fine.  When I route to my Index in Orchard, It no longer works.  I can route to IndexCompleted, so I know the route is correct.  After digging thru a bit more of Orchard forums, I saw that Autofac is being used as an IoC container for controllers.

I am now looking at the Autofac as to what the problem may be.  0xB33f is having a similar issue where his will not work either.  After reading thru some of the Autofac problems, I saw that someone else had a problem with Autofac and AsyncControllers, and he had to code around the problem.  Its my personal belief after reading thru the Autofac code (specifically the ExtensibleActionInvoker.cs that it will handle an AsyncController.  (Read the code and comments here:  http://pastie.org/2137426 ), however I don't know where in Orchard the container is registered and added to the filter list. 

So, I've done my homework, I'm fairly certain nobody else has implemented one, and the secret behind this is actually locked away in Nicolas Blumhardt's head or in some obscure documentation file.   For the modification I want to use, it requires an AsyncController.  Now, Sharp, if you want to try to try it out, by all means, go for it.  Test my theory.  I need an example on how to make this controller work..  As it stands, I don't see an actual example of someone using an AsyncController on the net using Autofac.  Just a work around.

However, if you can figure out where to register the types that i posted in my pastie I linked, I'd appreciate it.  I'm not intimate enough with Orchard to figure it out on my own, so I'm bowing the the expertise of the developers or team members.

Let me know what parts of this you would like further explained.  I'm 110% motivated to figure this out.  I thought I was having routing problems before, but it's not.. and now i'm trying to dig deeper to fully understand whats going on.

Jun 29, 2011 at 10:40 AM

Orchard uses Autofac as an IoC container for everything, not just Controllers. It sounds like there just hasn't been support implemented in Orchard for AsyncController, and this is probably just an omission rather than any serious technical limitation on either side.

Asking the Autofac team isn't really going to help, unless it's clearly an issue with their product. Until you know where the actual problem is here, the assumption would be that it's on Orchard's side, not Autofac.

A lot of the IoC registry happens in Orchard.Framework/Environment so that's where to start looking, but I've barely investigated any of that part so I can't really give any pointers.

But, what you probably want to do first is raise a workitem on the Orchard issue tracker for "AsyncController doesn't work", and you might find out if it's something the team are aware of, or even if they've already implemented it.

Then if you get anywhere modifying Orchard's core registry to support them, you could submit that as a patch back to the project. It could be as straightforward as registering the AsyncController type with Autofac, it'll probably only have Controller registering right now. Although it could be a bit more in depth than that.

Jul 1, 2011 at 6:07 AM

Pete,

Appreciate the advice.  Before I put in a work item, I want to try to track down if the issue is in the version of Autofac that is being used by Orchard, or if the controller type is not setup in the configuration, etc..  I hate it when people tell me something 'doesn't work' but can't describe the error to me.  Ideally, this may be a patch contribution when I'm all done figuring this out.  I just want to make sure that I've exausted the community resources first (both Orchard and Autofac).  Who knows.. this may be as simple as updating the version of Autofac in Orchard, and then adding some code to ContainerBuilder to handle these.  At any rate,

Nosing around the Autofac forums tho, I have seen that AsyncControllers were first introduced around trunk 2.2 ( https://groups.google.com/d/topic/autofac/zHFHOImeogA/discussion ) And they were still waiting for a good implementation of it.

If you read this post, there was some talk about it as well.. (https://groups.google.com/d/topic/autofac/6RP8tIXhJ3I/discussion) which references 2.4 and AsyncControllers and may or may not be working.. At any rate, the functionality that I am trying to achieve may not be possible with the current builds that are in use.

Jul 5, 2011 at 10:39 PM

Hi,

Orchard appears to register its own IActionInvoker, called Orchard.Mvc.Filters.FilterResolvingActionInvoker.

This class derives from ControllerActionInvoker. At a guess, in order to support async actions, it should instead derive from AsyncControllerActionInvoker.

Hope this helps!

Nick

Jul 8, 2011 at 6:10 AM
Edited Jul 9, 2011 at 11:33 PM

Thanks Nick,

I looked more at his code after writing this... then read alot more.  So, in the FilterResolvingActionInvoker class that is in Orchard, they will need to also create a reference to the System.MVC.Async.AsyncControllers for this to work.

Looks like i'll be putting in a work request. 

~Dan