Copied to clipboard

Flag this post as spam?

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


  • Mahmoud 15 posts 85 karma points
    May 25, 2022 @ 07:05
    Mahmoud
    0

    Using Umbraco 8 with Autofac

    Hi, I'm migrating from Umbraco 7 to 8 and I'm using Autofac as my dependency injection framework, but actually Umbraco 8 came with LightInject as a built in dependency injection library.

    Does that mean that I need to use LightInject instead and refactor all my code to adapt to this? I believe there should be a way so that we can use our preferred DI framework but I couldn't find any in the documentatio?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 25, 2022 @ 07:21
    Dave Woestenborghs
    0

    Hi Mahmoud,

    In theory it should be possible to replace light inject by autofac (I think), by creating your own implementation of the IRegister interface : https://github.com/umbraco/Umbraco-CMS/blob/v8/dev/src/Umbraco.Core/Composing/IRegister.cs

    This is the Light Inject implementation : https://github.com/umbraco/Umbraco-CMS/blob/v8/dev/src/Umbraco.Core/Composing/LightInject/LightInjectContainer.cs

    You then need to tell Umbraco to use it by setting some app settings : https://github.com/umbraco/Umbraco-CMS/blob/v8/dev/src/Umbraco.Core/Composing/RegisterFactory.cs#L24

    But honestly, I think the safer and quicker solution is to use the default umbraco DI setup.

    Dave

  • Mahmoud 15 posts 85 karma points
    May 25, 2022 @ 07:42
    Mahmoud
    0

    Thanks Dav, I'm quite disappointed as it should be normal to configure another DI framework without such customizations. I hope they take that into consideration in the upcoming releases.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 25, 2022 @ 07:46
    Dave Woestenborghs
    0

    Hi Mahmoud,

    For V9 they are using MS DI. So no external DI framework is used there.

    Can I ask why you want to use Autofac, instead of the default Umbraco setup.

    When working on V7 projects in the past I also used Autofac. But when we switched over to V8 I always used the built in container (LightInject). Having built over 50 websites on V8 I never had any issues with that. I even never needed to access the concrete container, but only used the Umbraco API to register dependencies.

    Dave

  • Mahmoud 15 posts 85 karma points
    May 25, 2022 @ 11:07
    Mahmoud
    0

    Hi David, As you mentioned I'm already using Autofac in my project and I don't have any issues with it at the moment. I didn't dig deep the exact differences between both frameworks. Just not comfortable with the idea that we need to change our DI framework just because Umbraco doesn't support that out of the box. It's unnecessary code change from my point of view. Even in .Netcore you can use the default DI or your preferred one without doing customizations .

Please Sign in or register to post replies

Write your reply to:

Draft