Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian Rush 25 posts 95 karma points
    Jul 12, 2017 @ 18:30
    Brian Rush
    0

    Dependency Injection

    What do I need to register if I am using AutoFac and dependency Injection?

    Here is what I have now

    builder.RegisterApiControllers(typeof(RankOne.Controllers.AnalysisApiController).Assembly);
                builder.RegisterApiControllers(typeof(RankOne.Controllers.AnalyzerStructureApiController).Assembly);
                builder.RegisterApiControllers(typeof(RankOne.Controllers.DashboardApiController).Assembly);
                builder.RegisterApiControllers(typeof(RankOne.Controllers.PageApiController).Assembly);
    

    The issue I am running into is when I load the the Seo Rank One tab I get the following exception

    {"Message":"An error has occurred.","ExceptionMessage":"An error occurred when trying to create a controller of type 'DashboardApiController'. Make sure that the controller has a parameterless public constructor.","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DashboardApiController (ReflectionActivator), Services = [RankOne.Controllers.DashboardApiController], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An exception was thrown while invoking the constructor 'Void .ctor()' on type 'DashboardApiController'. ---> Could not load file or assembly 'HtmlAgilityPack, Version=1.4.9.5, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (See inner exception for details.) (See inner exception for details.)","ExceptionType":"Autofac.Core.DependencyResolutionException","StackTrace":" at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)\r\n at Autofac.Core.Resolving.InstanceLookup.Execute()\r\n at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)\r\n at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)\r\n at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)\r\n at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)\r\n at Autofac.Integration.WebApi.AutofacWebApiDependencyScope.GetService(Type serviceType)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"An exception was thrown while invoking the constructor 'Void .ctor()' on type 'DashboardApiController'. ---> Could not load file or assembly 'HtmlAgilityPack, Version=1.4.9.5, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (See inner exception for details.)","ExceptionType":"Autofac.Core.DependencyResolutionException","StackTrace":" at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()\r\n at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)\r\n at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Could not load file or assembly 'HtmlAgilityPack, Version=1.4.9.5, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)","ExceptionType":"System.IO.FileLoadException","StackTrace":" at RankOne.Helpers.HtmlHelper..ctor()\r\n at RankOne.Services.PageAnalysisService..ctor()\r\n at RankOne.Services.AnalyzeService..ctor()\r\n at RankOne.Helpers.PageScoreNodeHelper..ctor()\r\n at RankOne.Services.DashboardDataService..ctor()\r\n at lambda_method(Closure , Object[] )\r\n at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()"}}}} 
    
  • paulthorpe 10 posts 193 karma points
    Jul 13, 2017 @ 14:32
    paulthorpe
    0

    My AutoFaC setup is as follows

    var builder = new ContainerBuilder();
    builder.RegisterInstance(ApplicationContext.Current).AsSelf();
    builder.RegisterControllers(Assembly.GetExecutingAssembly());   
    builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
    
     builder.RegisterType<class>().As<interface>().InstancePerRequest();
    
    
    
    var container = builder.Build();
    
    var resolver = new AutofacWebApiDependencyResolver(container);
    
    GlobalConfiguration.Configuration.DependencyResolver = resolver;
    
    DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    
  • Mark Wemekamp 73 posts 385 karma points
    Jul 15, 2017 @ 08:06
    Mark Wemekamp
    0

    Hi, What exactly are you trying to achieve?

    Haven't used autofac myself yet, so I'm afraid I can't help you with this problem.

    The source code of the package is available on github, maybe it will help you with this

    https://github.com/markwemekamp/RankOne-Umbraco-SEO-Tool

Please Sign in or register to post replies

Write your reply to:

Draft