How to get rid of Autofac error?

63 Aufrufe
Direkt zur ersten ungelesenen Nachricht

tesicg

ungelesen,
04.09.2014, 03:53:5204.09.14
an aut...@googlegroups.com

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)
    {
    }

Travis Illig

ungelesen,
04.09.2014, 09:53:0204.09.14
an aut...@googlegroups.com
You're missing a registration. I see you registered IConcertDb, but where's IConcertHttpContext getting registered? Alternatively, you could register HttpContext or HttpContextBase. Either way, you're one registration short.

-T
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten