0

In my MVC web-app I get the following error thrown:

The request lifetime scope cannot be created because the HttpContext is not available

When I google it I found a solution would be to upgrade my autofac.Mvc dll but I only use autofac dll, Autofac.Integration.Mvc dll etc and I can't find any dll with autofac.MVC Am I missing any dll?

What is the difference between Autofac , Autofac.MVC ,Autofac.Integration.Mvc dlls?

Kasia Gogolek
  • 3,374
  • 4
  • 33
  • 50

2 Answers2

2

The documentation on MVC integration may be of help to you going forward, but let me also answer your question.

First, it's good to understand that there's a difference between NuGet packages and DLLs (aka assemblies). Many times the name of the assembly inside a NuGet package is the same as the package, but sometimes the assembly inside has a different name. (And sometimes a NuGet package has more than one assembly.)

So, to answer your question:

NuGet Package  Assembly Inside              Purpose
-------------  ---------------------------  -------------------------
Autofac        Autofac.dll                  Core Autofac
Autofac.Mvc5   Autofac.Integration.Mvc.dll  ASP.NET MVC 5 integration

So, when you see that you need to update your MVC integration, what it translates to is that you need the latest version of the Autofac.Mvc5 NuGet package.

Travis Illig
  • 23,195
  • 2
  • 62
  • 85
0

Autofac.mvc is used when you integrate autofac to your mvc application same as the autofac. WebAPI which is used when you integrate autofac for WebAPI's application. MVC integration provides dependency injection integration for controllers, model binders, action filters, and views. It also adds per-request lifetime support.

Because the RegisterModelBinders() extension method uses assembly scanning to add the model binders you need to specify what type(s) the model binders (IModelBinder implementations) are to be registered for. This is done by using the Autofac.Integration.Mvc.ModelBinderTypeAttribute Likewise there are many other mvc integration supported by this dll, which are listed down in this link https://autofac.org/apidoc/html/F26C16A.htm

Autofac lets you inject your constructor parameters along with property and method injection

Hence we need all three dlls to make autofac up and functional in mvc application.

Do let me know if you need any further clarification on this.

Thanks!!

Sweta Nair
  • 146
  • 6