Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Best way to combine Web API & Blazor Web App in a monolithic solution using clean architecture? [closed]

$
0
0

I know there's been a couple posts about it online but I can't seem to find the answer I'm looking for.

I'm using clean architecture and therefore I'm paying close attention to project references and stuff and for this I'm trying to figure out how these two should work while being in the same solution.

my project goes as such:

App.API ( ASP.NET Core Web API )App.ApplicationApp.DomainApp.InfrastructureApp.UI ( Blazor Web App )

Here's my API's Program.cs class so far:

internal class Program{    private static async Task Main(string[] args)    {        IConfigurationRoot configuration = new ConfigurationBuilder()            .SetBasePath(Directory.GetCurrentDirectory())            .AddJsonFile("appsettings.json")            .Build();        CancellationToken cancellationToken = new CancellationToken();        IPasswordHasher passwordHasher = new PasswordHasher();        var builder = WebApplication.CreateBuilder(args);        var servicesSetup = builder.Services;        servicesSetup.AddApplication();        servicesSetup.AddInfrastructure(configuration);        servicesSetup.AddControllers().AddNewtonsoftJson(options =>        {            options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;        });        builder.Services.AddEndpointsApiExplorer();        builder.Services.AddSwaggerGen();        var app = builder.Build();        // Configure the HTTP request pipeline.        if (app.Environment.IsDevelopment())        {            app.UseSwagger();            app.UseSwaggerUI();        }        using (var scope = app.Services.CreateScope())        {            var services = scope.ServiceProvider;            await DataHelper.ManageDataAsync(services, cancellationToken);            try            {                var userManager = services.GetRequiredService<UserManager<ApplicationUser>>();                var roleManager = services.GetRequiredService<RoleManager<ApplicationRole>>();                await CreateRoles.SeedAsync(                    userManager,                    roleManager,                    configuration,                    passwordHasher);            }            catch (Exception ex)            {                // throw new Exception($"DIDN'T SEED NOR CREATED ROLES {ex}");            }        }        app.UseRouting();        app.UseHttpsRedirection();        app.UseAuthorization();        app.MapControllers();        app.Run();    }}

Here are my questions:

  • Should the Blazor web app call API's controllers methods by having a project reference to it or something ?
  • If so or if in a different way, how does Blazor call the API ? Does it even call the API or does it use its own URIs/controller methods ? I'm used to have 2 projects and call the API using the httpclient but this time I'm going monolithic.
  • If it were to be each their own controller, wouldn't it be easier to just use one endpoint per action ?
  • How should I wire them in their respective Program.cs ?
  • Is there any detail or piece of knowledge I should know to make sure they work well and avoid issues ?

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>