0

I'm attempting to implement Autofac (first time implementing) into an ASP.NET MVC 4.5 application and the second line of code in this example already has me stumped.

http://docs.autofac.org/en/latest/integration/mvc.html#quick-start

I'm in the Startup.cs class and configuration manager. I can't get it to recognize MvcApplication? Is that a pseudo for something? It has been in every example I can find. Did I miss a reference?

Thanks in advance.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
Danny Ellis Jr.
  • 1,674
  • 2
  • 23
  • 38

2 Answers2

2

The example is based on the default Visual Studio MVC template(s), which create a Global.asax.cs file with the following class:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();
    }
}

Technically, you don't need this class - you can move everthing to Startup.cs and delete it. The reference to the class is just to get a reference to the MVC assembly, so you can technically use any type in your MVC project (such as the Startup class).

Community
  • 1
  • 1
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
-2

You are surely using asp.net Core and MVC6. If that's correct, then you don't need AutoFac; Dependency Injection is built-in by default.

Golois Mouelet
  • 307
  • 2
  • 10