Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 952 karma points
    Jan 31, 2017 @ 00:42
    Tom
    0

    Right way to get an instance of DataTypeService 7.5.8

    Hi All, We have just upgraded to 7.5.8 and are using the datatypeservice as part of a migration.

    I was wondering what the right way to grab an instance of it was whereas previously it looked like:

    var dts = new DataTypeService(); var dropdownValueToSet = dts.GetPreValuesCollectionByDataTypeId(templateVariantsDropdownDatatypeId).PreValuesAsDictionary .First(d => d.Value.Value == templateVariantName).Value.Id;

    The method sig has changed and I'm not sure how to initialise the dependencies for the UOW, repository factory etc.

    Thanks :)

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Jan 31, 2017 @ 11:03
    Alex Skrypnyk
    100

    Hi Tom

    The best way is to use standalone context of Umbraco like:

    var dropdownValueToSet = ApplicationContext.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(templateVariantsDropdownDatatypeId).PreValuesAsDictionary.First(d => d.Value.Value == templateVariantName).Value.Id;
    

    You don't need to create a new instance of Services I think.

    Just use what we have in context.

    Thanks

    Alex

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Jan 31, 2017 @ 17:45
    Alex Skrypnyk
    0

    Hi Tom

    Did you find solution?

    Is it working for you?

    Thanks,

    Alex

  • Tom 713 posts 952 karma points
    Jan 31, 2017 @ 20:36
    Tom
    0

    Hi Alex, Yes that worked perfectly thanks very much :)

  • 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