Copied to clipboard

Flag this post as spam?

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


  • Alistair Graham 22 posts 62 karma points
    Aug 23, 2019 @ 13:32
    Alistair Graham
    0

    Dependency Injection Umbraco 8

    Hi All

    Currently using Umbraco 8 for the first time. In previous Umbraco 7, I used Structure Map for our dependency injection.

    I know that Umbraco 8 it comes with light inject. However I used to use, ConnectImplementationsToTypesClosing and AddAllTypesOf in structure map. During umbraco start up.

    Does anyone know if there's an alternative to this in LightInject in Umbraco 8? Or how I can use structure map instead of light inject

    Thanks

    Ali

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Aug 23, 2019 @ 15:20
    Shaishav Karnani from digitallymedia.com
    0

    Hi Alistair,

    Given you have understanding of Structure Map IOC then Light Inject would be easier for you to pickup. In Umbraco 8, LightInject is the engine that they do use to implement IoC.

    I have tried Light Inject and I am delighted to discover the new features.

    Cheers,

    Shaishav

  • Alistair Graham 22 posts 62 karma points
    Aug 27, 2019 @ 09:47
    Alistair Graham
    0

    Just found this in the Registry Factory.

    /// To override the default LightInjectContainer, add an appSetting named 'Umbraco.Core.RegisterType' with /// a fully qualified type name to a class with a static method "Create" returning an IRegister.

    Going try that

  • Alistair Graham 22 posts 62 karma points
    Sep 05, 2019 @ 11:27
    Alistair Graham
    0

    Using the above we have attempted to create a structure map container and came across issues where Umbraco dependencies were not registering. We, therefore, have now reverted back to light inject and created extension methods.

    We are struggling to register all implementations of a given generic type. For example, given a base class or interface with generic parameters, register all implementations that derive from the base class

    This is/was achievable in StructureMap using assembly scanning:

    scan.ConnectImplementationsToTypesClosing(typeof(IRepository<>));
    

    As far as I can see, there is no way to do this with LightInject, meaning I would have to register each and every implementation of the base class

    We have tried the following without success

    https://stackoverflow.com/questions/48780797/using-lightinject-to-register-all-classes-that-implement-a-generic-interface?rq=1

    Struggling to identify a solution to this, does anyone have any ideas

  • Johan 1 post 71 karma points
    Sep 08, 2019 @ 08:18
    Johan
    0

    Same for us, struggling with transition from StructureMap to LightInject. We want to accomplish this (from StructureMap):

    // Scan adapters for Command/Query handlers.
            container.Configure(
                x => x.Scan(
                    y =>
                    {
                        y.Assembly("AssemblyX");
                        y.Assembly("AssemblyY");
                        y.Assembly("AssemblyZ");
                        y.AddAllTypesOf(typeof(ICommandHandler<>));
                        y.AddAllTypesOf(typeof(IQueryHandler<,>));
                        y.WithDefaultConventions();
                    }));
    
  • Paul Johnson 18 posts 109 karma points
    Jan 24, 2020 @ 14:17
Please Sign in or register to post replies

Write your reply to:

Draft