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 20 posts 40 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 277 posts 1264 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 20 posts 40 karma points
    27 days ago
    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 20 posts 40 karma points
    18 days ago
    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
    15 days ago
    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();
                    }));
    
Please Sign in or register to post replies

Write your reply to:

Draft