I recently attended .NET Conf 2023 where Aspire in .NET was introduced. I am working on a project and need guidance on how to set up multiple endpoints in a solution using Aspire. Currently, all three endpoints are connecting to a local SQL Server.
I want to modify the configuration so that all three endpoints connect to a single SQL Server. I would like to establish a dependency between these three endpoints and the SQL Server, making it easy to launch all three endpoints simultaneously. The endpoints are of type MVC ASP.NET.
My AppHost program.cs code :
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.CarRental_EndPoint_Admin_Web>("admin");
builder.AddProject<Projects.CarRental_EndPoint_Renter_Web>("renter");
builder.AddProject<Projects.CarRenter_EndPoint_Rentor_Web>("rentor");
builder.Build().Run();
- How can I configure a shared SQL Server connection that serves as a dependency for all three endpoints?
- Once the SQL Server dependency is established, how can I access and use it within each endpoint's code?
just go ahead to code.
AppHost Program.cs:
and add
builder.AddSqlServerDbContext<DataBaseContext>("CarRental");to my endpoints.