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 6 posts 97 karma points
    Apr 16, 2021 @ 20:59
    Sebastian Felis

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


    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 6 posts 97 karma points
    27 days ago
    Sebastian Felis

    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: