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

How do I check the "App Services / Domain Services" rule? #205

Open
max-arshinov opened this issue Feb 24, 2023 · 1 comment
Open

How do I check the "App Services / Domain Services" rule? #205

max-arshinov opened this issue Feb 24, 2023 · 1 comment
Assignees
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@max-arshinov
Copy link

image

I want to make sure that Application Services don't call other Application Services and call DomainServices instead.

private IObjectProvider<Class> AppServices = Classes().That().HaveName(@"\S+AppService", true);

//...

Classes().That().Are(AppServices).Should().NotCallAny(
  MethodMembers().That().AreDeclaredIn(AppServices)
);

However, code like this violates this rule

public class MyAppService
{
    public void Smth(){}

    public void SmthElse()
    {
      Smth();
    }
}

Is there a way to exclude "self" from the rule? If not, is there any other workaround?

@alexanderlinne alexanderlinne added the kind/support Categorizes issue or PR as a support question. label Mar 22, 2024
@alexanderlinne
Copy link
Collaborator

Hello @max-arshinov, a workaround at this time would be:

var AppServices = Classes().That().HaveName(@"\S+AppService", true);
foreach (var appService in AppServices.GetObjects(ARCHITECTURE))
{
    Classes()
        .That()
        .Are(AppServices)
        .And()
        .AreNot(appService)
        .Should()
        .NotCallAny(MethodMembers().That().AreDeclaredIn(appService))
        .Check(ARCHITECTURE);
}

or similarly:

var AppServices = Classes().That().HaveName(@"\S+AppService", true);
foreach (var appService in AppServices.GetObjects(ARCHITECTURE))
{
    Classes()
        .That()
        .Are(appService)
        .Should()
        .NotCallAny(
            MethodMembers()
                .That()
                .AreDeclaredIn(AppServices)
                .And()
                .AreNotDeclaredIn(appService)
        )
        .Check(ARCHITECTURE);
}

We have a similar case in #229 where self references lead to such a problem and are working on a solution.

@alexanderlinne alexanderlinne self-assigned this Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

2 participants