Copied to clipboard

Flag this post as spam?

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


  • Javz 38 posts 141 karma points
    May 17, 2020 @ 22:22
    Javz
    0

    Injecting Models Builder generated Models

    Hi,

    I've used the models builder to generate the document types as models within the solution, setting the config to "LiveAppData"

    I've set some as compositions, so I can then inject them in custom services, as there are generated as interfaces as well.

    When injecting these into a custom service, I get following error:

        Boot failed: Umbraco cannot run. See Umbraco's log file for more details.
    
        -> Umbraco.Core.Exceptions.BootFailedException: Boot failed.
    
        -> System.InvalidOperationException: Unable to resolve type: Umbraco.Core.Composing.ComponentCollection, service name:   at LightInject.ServiceContainer.CreateDelegate(Type serviceType, String serviceName, Boolean throwError)   at LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boolean throwError)   at LightInject.ServiceContainer.GetInstance(Type serviceType)   at Umbraco.Core.FactoryExtensions.GetInstance[T](IFactory factory)   at Umbraco.Core.Runtime.CoreRuntime.Boot(IRegister register, DisposableTimer timer)
    
    ...
    
    -> System.InvalidOperationException: Unresolved dependency [Target Type: Services.Excel.GraphService], [Parameter: microsoftGraphApi(Umbraco.Web.PublishedModels.IMicrosoftGraphApicomposition)], [Requested dependency: ServiceType:Umbraco.Web.PublishedModels.IMicrosoftGraphApicomposition, ServiceName:]
      at LightInject.ServiceContainer.GetEmitMethodForDependency(Dependency dependency)
      at LightInject.ServiceContainer.EmitConstructorDependency(IEmitter emitter, Dependency dependency)
      at LightInject.ServiceContainer.EmitConstructorDependencies(ConstructionInfo constructionInfo, IEmitter emitter, Action`1 decoratorTargetEmitter)
      at LightInject.ServiceContainer.EmitNewInstanceUsingImplementingType(IEmitter emitter, ConstructionInfo constructionInfo, Action`1 decoratorTargetEmitMethod)
      at LightInject.ServiceContainer.EmitNewInstance(ServiceRegistration serviceRegistration, IEmitter emitter)
      at LightInject.ServiceContainer.<>c__DisplayClass153_0.<CreateEmitMethodWrapper>b__0(IEmitter ms)
      at LightInject.ServiceContainer.<>c__DisplayClass153_0.<CreateEmitMethodWrapper>b__0(IEmitter ms)
      at LightInject.ServiceContainer.EmitConstructorDependency(IEmitter emitter, Dependency dependency)
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    

    In previous versions, I would get the data of the page via the interface, through a generic class where it gets the Id as well - the Umbraco 8 version of that code also threw the same error as above.

    Is there a way for me to successfully inject these interfaces and use them in my custom service class?

    I'm injecting as the following:

        private readonly IMicrosoftGraphApicomposition _microsoftGraphApi;
        public GraphService(ILogger logger, IMicrosoftGraphApicomposition microsoftGraphApi)
        {
            _logger = logger;
            _microsoftGraphApi = microsoftGraphApi;
        }
    

    Thanks

    As a workaround, I'm using the Concrete model and getting the path based on the alias of the document type to get the values of the item:

        var publishedContent = Umbraco.Web.Composing.Current.UmbracoHelper.ContentSingleAtXPath("//"+MicrosoftGraphApi.ModelTypeAlias);
        var microsoftGraphApisettings = new MicrosoftGraphApi(publishedContent);
    
Please Sign in or register to post replies

Write your reply to:

Draft