Copied to clipboard

Flag this post as spam?

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


  • Sebastian Felis 9 posts 127 karma points
    Apr 16, 2021 @ 20:59
    Sebastian Felis
    0

    Get many instance of interface with Our.Umbraco.IoC.LightInject4 for Umbraco 7

    Hi,

    I need get meny objects implementing specify interface using Our.Umbraco.IoC.LightInject4, but when I try to do it using GetAllInstances() method it alwasy return me colection of one containing only the last registrated type of this interface.

    I make something like this in Composition Root:

    foreach (var format in TypeFinder.FindClassesOfType<IQRCodeFormat>())
    {
         serviceRegistry.Register(typeof(IQRCodeFormat), format, new PerRequestLifeTime());
    }
    
    serviceRegistry.Register(f => new QRCodeFormatsCollection(f.GetAllInstances<IQRCodeFormat>()), new PerRequestLifeTime());
    

    I'd check EnableVariance option in container's options and it's set to true so LightInject should support this case.

    Maby someone know what I do wrong?

  • Sebastian Felis 9 posts 127 karma points
    Apr 19, 2021 @ 11:49
    Sebastian Felis
    0

    Ok, I found my mistake. I'd missing service name in Register method. So it should be:

    serviceRegistry.Register(typeof(IQRCodeFormat), format, format.Name, new PerRequestLifeTime());
    
Please Sign in or register to post replies

Write your reply to:

Draft