I have installed autoFac and AutoFac.Mvc5 both but RegisterControllers() method is not Available

221 Views Asked by At

here is screenshot of IDE I have installed autofac and autofac.mvc5 both packages but RegisterControllers() method is not available and also "Using AutoFac.Integeration.Mvc" Namespace not accessible and showing error.

here is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OdoFood.Data.Services;
using System.Reflection;
using Autofac;
using Autofac.Integration.Mvc;

namespace OdoFood.Web
{
    public class ContainerConfig
    {
        internal static void RegisterContainer()
        {
            var builder = new ContainerBuilder();
            builder.RegisterController(typeof(MvcApplication).Assembly);
            
            
        }

       
    }
}
2

There are 2 best solutions below

2
Travis Illig On

Your code...

            var builder = new ContainerBuilder();
            builder.RegisterController(typeof(MvcApplication).Assembly);

...says RegisterController (singular) not RegisterControllers (plural). Add an s on the end of that.

0
Amadeus On

I had the same problem and these steps solved the problem:

  1. Uninstall all Autofac libraries
  2. Install Autofac
  3. Install Autofac.Mvc5