Copied to clipboard

Flag this post as spam?

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


  • Shuchita 45 posts 154 karma points
    May 01, 2023 @ 05:28
    Shuchita
    0

    After upgrade Umbraco 7.15 to 8.5.5 (Autofac to LightInject dependencies are not working)

    Hi,

    I have upgraded Umbraco 7.15 to 8.5.5. After upgrade that Autofac dependencies was not working because .net framework does not support it. So I have tried LightInject, which is I think alternate of Autofac.

    But LightInject not resolve all the dependencies same as Autofac. e.g.

     public T Resolve<T>(string key = "", Scope scope = null) where T : class
    {
        if (scope == null) scope = Scope();
        return string.IsNullOrEmpty(key) ? scope.GetInstance<T>() : scope.GetInstance<T>(key);  
    }
    

    enter image description here enter image description here

    Please suggest me what I can do here to resolve this issue.

    Thanks.

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    May 01, 2023 @ 15:40
    Marc Goodson
    0

    Hi Shuchita

    There is a good introduction to lightinject in V8 here:

    https://our.umbraco.com/Documentation/Reference/Using-Ioc/

    I think you need to do less than with autofac to wire things up.

    Hopefully that might give you some insights in how to move from one DI framework to the other...

    regards

    marc

  • Shuchita 45 posts 154 karma points
    May 08, 2023 @ 05:21
    Shuchita
    0

    Hi Marc,

    Thank for the reply. I have already tried the example you have shared e.g.

    var serviceContainer = composition.Concrete as LightInject.ServiceContainer;
     serviceContainer.Register<IWorkContext, WorkContext>(new PerContainerLifetime());
    

    It is not working. There are some custom services used like below screenshot and throwing error: This line is throwing error in the Resolve T function:

      var workContext = IpfExtraNetEngineContext.Current.Resolve<IWorkContext>();
    

    enter image description here

    Resolve T is using in whole project and without resolving dynamic dependencies it will not work. Please suggest if any way to fix it?

    Thank you.

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    May 08, 2023 @ 19:50
    Marc Goodson
    100

    Hi Shuchita

    Are you trying to service locate IWorkContext?

    if so

    using Current = Umbraco.Web.Composing.Current;
    
    
    var workContext = Current.Factory.GetInstance<IWorkContext>();
    

    might be what you need, if IWorkContext is registered as you have above with the DI container?

    Or are you expecting all your dependencies to be autoscanned? if so there is an interesting long debate regarding that for V8 https://github.com/umbraco/Umbraco-CMS/issues/7502

    regards

    Marc

  • Shuchita 45 posts 154 karma points
    May 11, 2023 @ 05:08
    Shuchita
    0

    Hi Marc,

    This is working at my end Current.Factory.GetInstance<IWorkContext>()

    Thank you so much.

  • Angelo 20 posts 72 karma points
    Oct 13, 2023 @ 07:50
    Angelo
    0

    Hi Shuchita, Please message me. I need your help developing Umbarco 12 site. parttime/fulltime rishi at osho net

Please Sign in or register to post replies

Write your reply to:

Draft