Error when running Orchard (Autofac)

Topics: Troubleshooting
May 2, 2011 at 1:00 AM
Edited May 2, 2011 at 1:01 AM

Hi there,

We have been using Orchard 1.1.30 for our new website, up until now we havn't come accross any show stoppers, it been working fine. 

The other day, one of our devs got the latest branch from our source control and built the solution.  I should say that this process has worked previously on machines without any knowledge of Orchard or WebMatrix. Once built we recieved the following error when browsing to our home page.  This is really strange because this only happens on one machine.  We have spent a few days trying to solve this problem, any help would be appreciated.

Here is an image of the stack trace

Whilst debugging the application we found that during Application_Start the container is trying to request an instance of HttpContextBase which was registered in the WorkContextModule, however this is causing an error during the resolve.

i.e. the following labmda causes the exception

ctx=> ctx.Resolve<WorkContextProperty<HttpContextBase>>().Value

No scope matching the expression 'value(Autofac.Builder.RegistrationBuilder`3+<>c__DisplayClass0[Orchard.Environment.WorkContextProperty`1[System.Web.HttpContextBase],Autofac.Builder.ConcreteReflectionActivatorData,Autofac.Builder.SingleRegistrationStyle]).lifetimeScopeTag.Equals(scope.Tag)' is visible from the scope in which the instance was requested.

Coordinator
May 2, 2011 at 5:18 AM

When you say "latest branch" you mean latest checkin in some branch I suppose. Which one?

May 2, 2011 at 5:33 AM
Edited May 2, 2011 at 5:35 AM

Hey, sorry for the confusion by saying "latest branch" i am talking about Orchard 1.1 change set 48ba0ed3ac80

 

Update : After looking into the problem a little more we discovered that the problem was being caused by incorrect registration in the container

I created the following class that is responsible for registering our dependencies from within our Module

 

public class DefaultModule : Module {   

   protected override void Load(ContainerBuilder builder)    {       

 builder.RegisterType<MembershipService>().As<IMembershipService>();       

 builder.RegisterType<MembershipRepository>().As<IMembershipRepository>();
 }

}

 

What is the best way of registering these components so that they have a per request lifestyle, I cannot implement IDependency as they are sealed classes,

Also what is the best way inject an instance of HttpContextBase, should i use IHttpContextAccessor or can i inject a HttpContextBase directly.

 

Cheers for you help.

Coordinator
May 2, 2011 at 7:00 AM

I'm sorry, making them implement IDependency is the way to go. Can you make a façade for these?

I'd use IHttpContextAccessor. Injecting a concrete implementation doesn't make a lot of sense, you might as well get HttpContext.Current.