.net maui (not hybrid) and blazored.localstorage: 1) will it work? and 2) How - can't seem to initialize injected service

153 views Asked by At

When I attempt to use Blazored.LocalStorage in my code library it never gets init'd and I can't seem to find a way to make that happen.

I know I'm missing something obvious here. To wit:

In MauiProgram.cs:

builder.Services.AddBlazoredLocalStorageAsSingleton();

In my library file:

using Blazored.LocalStorage;

...

public class MyLibrary
{
    [Inject]
    private static ILocalStorageService LocalStorage { get; set; }   // <-- obviously, not getting initialized

    public async static Task<string> GetLocalStorageAsync(string key)
    {
        string rtn = "";

        if (LocalStorage != null) // <-- always null
        {
            if (await LocalStorage.ContainKeyAsync(key))
            {
                rtn = await LocalStorage.GetItemAsStringAsync(key);
            }
        }

        return rtn;
    }

    // ...
}

Is it possible to initialize an injected service?

Thanks in advance!

0

There are 0 answers