Copied to clipboard

Flag this post as spam?

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


  • Rob Maas 8 posts 88 karma points
    May 01, 2019 @ 10:12
    Rob Maas
    0

    Composing - Configure constructor parameters and properties

    Hello,

    I'm trying to register some services in a IUserComposer, which works for very simple stuff but I'm missing a couple of necessary functions that I'm used to working with Autofac.

    I'm trying to configure the necessary constructor parameters and overwrite some properties of the created services.

    Autofac:

    builder.RegisterType<SomeType>().As<ISomeType>().WithParameters(new NamedParameter("param1", "somevalue"));
    

    and

    builder.RegisterType<SomeType>().As<ISomeType>().WithProperty("propName", someObject);
    

    Can anybody help me out with this?

    Rob

  • Corné Strijkert 77 posts 433 karma points
    May 01, 2019 @ 10:54
    Corné Strijkert
    0

    Hi Rob,

    Interesting question. I've looked at the Umbraco source code and I came to this:

    composition.Register<ISomeType>((factory) => 
        new SomeType("somevalue", 
            factory.GetInstance<ISomeOtherType1>(), 
            factory.GetInstance<ISomeOtherType2>()), Lifetime.Scope);
    

    I'm not sure if this is what you're searching for? Give it a try and I'm curious if it will work..

    I would suggest to search for 'Register' on the Umbraco 8 repository. You will get a lot of code samples how Umbraco is registering stuff. https://github.com/umbraco/Umbraco-CMS/search?q=Register&unscoped_q=Register

  • Rob Maas 8 posts 88 karma points
    May 08, 2019 @ 14:27
    Rob Maas
    0

    Hi Corné,

    Thank you for your reply.

    I took a look at the LightInject documentation, which was helpful.

    Found out most of my necessary third-party packages have no impl. support for LightInject IOC and didn't feel like creating all of them myself so I just ended up using Umbraco 7 with Autofac instead.

    It's a bit of a pity that Umbraco 8 uses a pretty much unknown library for its IOC if you'd ask me.

    Regards,

    Rob

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies