-
Hi! In my solution I have a project that is used as a "Shell" for all modules (each module has a collection of endpoints, like a microservice), the modules to load for an instance of this are passed by configuration. So the product can behave like a monolith or scale by selecting modules to deploy in separate when needed. The goal is to be able to have different deployment configurations based on the need of it and to grow in a easy and mor cost effective way, and then scale as needed. For example, in local dev I deploy all modules in the same running webapp, but by configuration I can run a different webapp for each module. I'm in a process of exploring Aspire, it seems a perfect tool for this kind of distributed projects, but I'm facing a issue here when trying to launch one instance per module. The pattern I'm using here (don't know if it is the best) is to declare the ProjectResources and setting the launchProfile for a specific value for each. This way I can use Env Variables on the specific launchprofile to tell what modules to load for each instance. This is the way I imagine to "pass data" from the Host to the running instances. var builder = DistributedApplication.CreateBuilder(args);
var apiGateway = builder.AddProject<Projects.Lynx_Backend_APIGateway>("apigateway");
var db = builder
.AddSqlServerContainer("dbServer")
.AddDatabase("db");
// Projects.Lynx_Backend_Host is the host project for every module
var moduleA = builder
.AddProject<Projects.Lynx_Backend_Host>("Core")
.WithLaunchProfile("core")
.WithReference(db);
var moduleB = builder
.AddProject<Projects.Lynx_Backend_Host>("HR")
.WithLaunchProfile("hr")
.WithReference(db);
apiGateway.WithReference(moduleA);
apiGateway.WithReference(moduleB);
builder.Build().Run(); On running this for 2 instances (each one will load a module and run), I get the following error:
Checking the source code I can see that this maybe not going to work, because it checks for projects with the "same path", and in my case they all are the same project running - just with different context. /// <summary>
/// Tries to get the project resource with the specified path from the distributed application model.
/// </summary>
/// <param name="model">The distributed application model.</param>
/// <param name="path">The path of the project resource.</param>
/// <param name="projectResource">When this method returns, contains the project resource with the specified path, if it is found; otherwise, null.</param>
/// <returns><see langword="true"/> if the project resource with the specified path is found; otherwise, <see langword="false"/>.</returns>
public static bool TryGetProjectWithPath(this DistributedApplicationModel model, string path, [NotNullWhen(true)] out ProjectResource? projectResource)
{
projectResource = model.GetProjectResources().SingleOrDefault(p => p.Annotations.OfType<IServiceMetadata>().FirstOrDefault()?.ProjectPath == path);
return projectResource is not null;
} Is this pattern some thing supported right now? Or in the future? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
That approach looks reasonable to be. Given that you do want to model launching the same code as different services. We just have a bug in this |
Beta Was this translation helpful? Give feedback.
-
How can you show a custom name in the dashboard for each instance of the same project? |
Beta Was this translation helpful? Give feedback.
That approach looks reasonable to be. Given that you do want to model launching the same code as different services. We just have a bug in this
TryGetProjectWithPath
implementation that assumes there would only be one project with this path. We should be able to solve this.