We have ASP.NET application where we use Autofac. The following error comes up:

None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'ConcertRu.ApplicationsCore.Services.SessionWebAppService' can be invoked with the available services and parameters:
Cannot resolve parameter 'System.Web.HttpContext httpContext' of constructor 'Void .ctor(System.Web.HttpContext)'.
Cannot resolve parameter 'System.Web.HttpContextBase httpContext' of constructor 'Void .ctor(System.Web.HttpContextBase)'.
Cannot resolve parameter 'ConcertRu.Infrastructure.Contracts.IConcertHttpContext httpContext' of constructor 'Void .ctor(ConcertRu.Model.Contracts.IConcertDb, ConcertRu.Infrastructure.Contracts.IConcertHttpContext)'.

Global.asax.cs:

// Create the container builder.
var builder = new ContainerBuilder();

// Register the Web API controllers.
builder.RegisterControllers(Assembly.GetExecutingAssembly());

// Register other dependencies.
var services = typeof(AccessTokenService).Assembly;
builder.Register(c => ConcertDb.Current).As<IConcertDb>().SingleInstance();
builder.RegisterAssemblyTypes(services)
        .Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces()
        .SingleInstance();

// Build the container.
var container = builder.Build();

// Create the depenedency resolver.
var resolver = new AutofacDependencyResolver(container);

// Configure Web API with the dependency resolver.
DependencyResolver.SetResolver(resolver);

The SessionWebAppService class:

public class SessionWebAppService : WebAppServiceBase, ISessionWebAppService
{
    public SessionWebAppService(HttpContext httpContext)
        : this(new ConcertDb(), new WebFormContext(httpContext))
    {
    }

    public SessionWebAppService(HttpContextBase httpContext)
        : this(new ConcertDb(), new MvcContext(httpContext))
    {
    }

    public SessionWebAppService(IConcertDb concertDb, IConcertHttpContext httpContext)
        : base(concertDb, httpContext)
    {
    }

Related posts

Recent Viewed