Copied to clipboard

Flag this post as spam?

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


  • Hein 29 posts 158 karma points
    Sep 25, 2017 @ 10:15
    Hein
    0

    Creation of new ContentService gives me an error

    I'll save new content programmatically and I use this code:

    private void CreateSubscription(string fullname, string company, string email, int eventId)
    {
        ContentService cs = new ContentService(); // <-- on this line
        var content = cs.CreateContent(_rnd.Next().ToString(), eventId, "subscription");
        content.SetValue("fullname", fullname);
        content.SetValue("email", email);
        content.SetValue("company", company);
    
        cs.Save(content);
    }
    

    I've taken it from here: Replay on Create new content nodes programmatically.

    But this gives me this error on the marked line:

    There is no argument given that corresponds to the required formal parameter provider of ContentService.ContentService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IEventMessagesFactory, IDataTypeService, IUserService)

    What do I wrong? I'm using Umbraco 7.7.

  • Nik 1617 posts 7263 karma points MVP 7x c-trib
    Sep 25, 2017 @ 10:43
    Nik
    1

    He Hein,

    There should be no need for you to create a new instance of the ContentService. Presumably you are putting this code inside a surface controller?

    If you are, you can access the ContentService from the ApplicationContext.

    See this documentation link for more details: https://our.umbraco.org/documentation/reference/management/services/contentservice

    In the Surface Controller, all services should also be available through the Services property. This saves you having to create your own ones :-)

    Hope that helps .

    Nik

  • Marcio Goularte 388 posts 1360 karma points
    Sep 25, 2017 @ 13:17
    Marcio Goularte
    1

    Access ContentService from ApplicationContent

    ApplicationContext.Current.Services.ContentService
    
Please Sign in or register to post replies

Write your reply to:

Draft