Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation: Ensure all utilized types are registered in DI #316

Closed
WhitWaldo opened this issue Jun 24, 2024 · 1 comment
Closed

Validation: Ensure all utilized types are registered in DI #316

WhitWaldo opened this issue Jun 24, 2024 · 1 comment

Comments

@WhitWaldo
Copy link

In a similar vein to what I'm trying to do in #315 , another of the validation checks I'd like to do spans multiple types and it's similarly unclear to me how I'd do it.

I would like to validate that every Dapr Workflow and Workflow Activity has been properly registered in the dependency injection framework (assuming Microsoft.Extensions.DependencyInjection for my immediate purposes). As part of the registration pipeline, this generally looks something like:

builder.Services.AddDaprWorkflow(opt => {
  opt.RegisterWorkflow<MyWorkflow>();
  opt.RegisterActivity<MyActivity>();
});

And that's it to registration. What I'm trying to identify at compile time is that each has been properly registered so I might prevent a runtime exception indicating that DI failed to inject one of the types.

Now, as it's possible developers could have types in their project that they don't actually mean to use, this is where I'd like to be able to do two checks:

  1. Identify every type that implements Workflow and within that type's RunAsync method, identify each invocation of CallActivityAsync and pull the name of the activity type out of the first argument (would generally just be a string value, but that's where Validation: Throw error if first argument in target method invocation doesn't use nameof() #315 comes in). Validate that a registration exists in the DI registration matching opt.RegisterActivity<WhateverThisActivityTypeIs>().

  2. Identify every type that implements Workflow. Scan the rest of the project for any invocation against a DaprWorkflowClient instance of ScheduleNewWorkflowAsync (or there are a few other invocation method names as well) in which the name of the Workflow type is passed into the first argument. Validate that for each of these Workflows used in the project, it's similarly registered in the DI framework via opt.RegisterWorkflow<MyWorkflow>();

Is it possible to do a full-project architectural validation like either of these goals?

Thank you!

@svick
Copy link
Member

svick commented Jun 24, 2024

I don't think there is an easy way to do this using Metalama. You could get access to the Roslyn syntax nodes and check those, but at that point, Metalama is not helping you much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants