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.
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 documentIAuthService, AuthServiceso 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