Copied to clipboard

Flag this post as spam?

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


  • Imran 17 posts 114 karma points c-trib
    Oct 11, 2019 @ 13:55
    Imran
    0

    FormStorage() inaccessible now in Forms for V8?

    Hi,

    I used to be able to access UmbracoForms data with FormStorage() like this:

    enter image description here

    But when trying to do this in V8 it seems like the accessibility level has been changed and I get the error of "'FormStorage' is inaccessible due to its protection level."

    enter image description here

    What is the new way of accessing the Forms storage, records data in V8 now?

  • Marc Goodson 2148 posts 14353 karma points MVP 8x c-trib
    Oct 13, 2019 @ 08:13
    Marc Goodson
    3

    Hi Imran

    FormStorage is now registered as a singleton with Umbraco V8's new lightject underlying dependency injection framework:

     composition.Register<IFormStorage, FormStorage>(Lifetime.Singleton);
    

    This means you can gain access to the FormStorage by injecting it into the constructor of the class you are working in:

    eg

      public class SomeCustomController : UmbracoAuthorizedJsonController
        {
            private readonly IFormStorage _formStorage;
    
    
            public SomeCustomController(IFormStorage formStorage)
            {
                _formStorage = formStorage;
            }
    

    Then you can use _formStorage in your methods..

    Failing that, eg you are choosing not to use DI, or it would be difficult to implement in your custom code then you can use the service locator pattern to retrieve the instance of IFormStorage:

    IFormStorage _formStorage = Current.Factory.GetInstance<IFormStorage>();
    

    regards

    Marc

  • Liam Dilley 156 posts 382 karma points
    Dec 15, 2020 @ 04:25
    Liam Dilley
    0

    May I ask what that would be in a Razor email template then?

Please Sign in or register to post replies

Write your reply to:

Draft