-
Notifications
You must be signed in to change notification settings - Fork 5
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
Comments
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
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:
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:
Identify every type that implements Workflow and within that type's
RunAsync
method, identify each invocation ofCallActivityAsync
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 usenameof()
#315 comes in). Validate that a registration exists in the DI registration matchingopt.RegisterActivity<WhateverThisActivityTypeIs>()
.Identify every type that implements Workflow. Scan the rest of the project for any invocation against a
DaprWorkflowClient
instance ofScheduleNewWorkflowAsync
(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 viaopt.RegisterWorkflow<MyWorkflow>();
Is it possible to do a full-project architectural validation like either of these goals?
Thank you!
The text was updated successfully, but these errors were encountered: