Replies: 1 comment 1 reply
|
Hi @datamweb, could you give example of code with namespace relation, I think most of usecase should be detected via something like: if ($classNode->isReferenced && ! $classNode->isInstantiated) {
return null;
}
return new RuleViolation( ... );That's referenced allowed, but not directly instantiated. You can implements the interface marker, for example: |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi @samsonasik ,
I’m using StructArmed to enforce the architectural boundaries of a CI4 package, and I have a question about enforcing dependency injection.
In my architecture, a service layer is allowed to depend on a repository abstraction, but I want to prevent the service from creating a concrete repository itself.
For example, conceptually, I want the architecture to distinguish between:
The important part is that the repository layer itself is allowed as a dependency of the service layer, so a normal layer dependency rule cannot distinguish these two cases.
I noticed that StructArmed exposes information indicating that a class has been instantiated, but what I really need for an architecture rule is the relationship between the source class/scope and the instantiated class.
In other words, I need the architecture analyser to be able to answer a question like:
Did this service directly instantiate this concrete dependency?
rather than only:
Was this class instantiated somewhere in the scanned code?
Ideally, a custom rule would be able to inspect something conceptually similar to:
SomeServicesomeMethodSomeConcreteRepositoryThis would allow a rule such as:
I’m wondering what the recommended way to implement this with StructArmed is.
Is there already a supported API for accessing this kind of instantiation provenance in a custom rule?
If not, is there another intended StructArmed approach for enforcing “dependency injection rather than direct instantiation” at the architectural level?
I would prefer to use the public StructArmed API rather than accessing the underlying AST directly.
Thanks!
All reactions