0

So I built a class library that I will use for various different projects in the future. Now when I want to implement it and set the options in my Program.cs file, my blazor app gets stuck on the Loading... page. I can't seem to find the problem or why this is occuring.

In my class library I have a model ConfigurationSettings and a class with a method to set the configuration settings.

 public class ConfigurationSettings
{
    public string ConnectionString { get; set; }
    public string Token { get; set; }
    public string Issuer { get; set; }
    public string Audience { get; set; }
}
 public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddLibrary(this IServiceCollection services, Action<ConfigurationSettings> configure)
    {
        services.Configure(configure);        
        services.AddDbContext<ApplicationDbContext>((provider, options) =>
        {
            var myLibraryOptions = provider.GetRequiredService<IOptions<ConfigurationSettings>>().Value;
            options.UseSqlServer(myLibraryOptions.ConnectionString);
        });

        return services;
    }
}

This configurationSettings will come from the main application implementing this class library.

In my Blazor Web Assembly application, I added the following to set the configurationSettings->

 builder.Services.AddLibrary(options =>
{
    options.ConnectionString = connectionString;

    IConfigurationSection configurationSettingsSection = builder.Configuration.GetSection("ConfigurationSettings");
    options.Token = configurationSettingsSection["Token"];
    options.Issuer = configurationSettingsSection["Issuer"];
    options.Audience = configurationSettingsSection["Audience"];
});
builder.Services.AddScoped<IAuthService, AuthService>();

Any suggestions on what I can possibly do to test and solve this issue as when I remove the above from my Program.cs everything works without issues.

5
  • if you are having a stand-alone blazor wsam project, then I'm afraid this answer can explain.. But this setup is not going to work. All Database operations have to happen on the Server. If you only want to consume a razor component from razor class library, then you might follow this official document Commented Dec 6, 2023 at 12:30
  • I am using Web Assembly hosted on server and the class library is added in my Server Project. Commented Dec 6, 2023 at 13:45
  • asp.net core hosted blazor web assembly project? Commented Dec 6, 2023 at 13:52
  • 1
    yes asp.net core hosted blazor web assembly project Commented Dec 7, 2023 at 6:19
  • I have a test which adding your code snippets into the class library and adding your code snippets into Program.cs in the asp.net core server project of the blazor wasm, everything worked fine. But Since you didn't provide the content of IAuthService, AuthService so I don't have that line in my project, I'm afraid you need to provide a minimal reproducible sample for troubleshooting. Or at least keep narrowing down the issue. i.sstatic.net/waXgP.png Commented Dec 7, 2023 at 7:47

1 Answer 1

0

So the error I later found was Uncaught SyntaxError: import.meta may only appear in a module

To solve this issue, I updated my visual studio, and all the nuget packages. It resolved the issue.

Sign up to request clarification or add additional context in comments.

1 Comment

ok that's fine... sounds great

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.