Copied to clipboard

Flag this post as spam?

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


  • Marc Love (uSkinned.net) 447 posts 1789 karma points
    Sep 29, 2015 @ 18:17
    Marc Love (uSkinned.net)
    1

    Testing 7.3 - ContentService c = new ContentService();

    I am currently testing Umbraco 7.3

    The following line causes an error which didnt happen in previous versions:

    ContentService c = new ContentService();
    

    The error is:

    'Umbraco.Core.Services.ContentService' does not contain a constructor that takes 0 arguments

    Anyone know why this no longer works in 7.3.

    Cheers,

    Marc

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Sep 29, 2015 @ 18:51
    Kevin Jump
    109

    Hi

    the Public empty constructor for ContentService appears to have gone in 7.3 the only constructor is now

     public ContentService(
                IDatabaseUnitOfWorkProvider provider,
                RepositoryFactory repositoryFactory,
                ILogger logger,
                IEventMessagesFactory eventMessagesFactory,
                IPublishingStrategy publishingStrategy,
                IDataTypeService dataTypeService,
                IUserService userService)
    

    which means you need a lot of other stuff to call it

    However i think calling ContentService this way is really only used when runing through the tests.

    if you want to get to a version of content service for the current umbraco instance you should call

    var contentService = ApplicationContext.Current.Services.ContentService;
    

    You will then have an instance of content service you can do anything you need to with.

  • Marc Love (uSkinned.net) 447 posts 1789 karma points
    Sep 30, 2015 @ 09:20
    Marc Love (uSkinned.net)
    1

    Thank you Kevin, all sorted now.

    You the man!!!

  • Zac 223 posts 575 karma points
    Oct 01, 2015 @ 16:52
    Zac
    0

    Just came across this after moving a site to 7.3.0, thanks for the solution Kevin!

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Nov 12, 2015 @ 22:26
    Jon R. Humphrey
    0

    Thanks Kevin!

    Spot on for me too; although I wish I had seen this about 4 hours ago!

    Cheers, Jon

  • Eric Schrepel 161 posts 226 karma points
    Feb 08, 2016 @ 20:13
    Eric Schrepel
    0

    I'm still unclear how to call ContentService from, say, a Partial View Macro, where I'd previously had just:

    var cs = new ContentService();
    

    I've tried the full ApplicationContext.Current.Services.ContentService line but that throws errors also (cannot be accessed with an Instance reference).

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Feb 08, 2016 @ 21:20
    Jon R. Humphrey
    0

    Erid,

    Do you have the @using Umbraco.Core set?

    Take a look at how I've been using the CS in my instance here if that helps?

    Jon

  • Pradip Chhwaju 5 posts 25 karma points
    Aug 17, 2016 @ 09:30
    Pradip Chhwaju
    0

    Hi Kevin,

    Wow, it 's really worked on latest versions of Umbraco onward 7.3.X.

    Thanks a lot Kevin.

  • René 327 posts 852 karma points
    Nov 24, 2016 @ 13:31
    René
    0

    Hi

    I forund this it helped me if others having trouble http://harveywilliams.net/blog/making-umbraco-nodes-with-the-models-builder

Please Sign in or register to post replies

Write your reply to:

Draft