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 the API's controllers methods by having a project reference to it or something ? In any case, how does Blazor call the API ? By calling its URIs/controller methods ?
- How should I wire them in their respective
Program.cs?
I'd like to know how to make it work because I know how to make it work when it's different projects but I've never done that in a monolithic application.