Skip to content

feat: Dependency injection with ValidatorProvider#862

Merged
lionel-nj merged 1 commit intoMobilityData:masterfrom
aababilov:validator-provider
Apr 22, 2021
Merged

feat: Dependency injection with ValidatorProvider#862
lionel-nj merged 1 commit intoMobilityData:masterfrom
aababilov:validator-provider

Conversation

@aababilov
Copy link
Copy Markdown
Collaborator

We pass a single ValidatorProvider object instead of ValidatorContext
and ValidatorLoader. This allows us to achieve a list of goals.

  1. Better modularity and testability. It is possible to inject a custom
    ValidatorProvider in the tests.
  2. Clients may provide their own validation for phones, emails etc.
  3. We open a way to define custom table header validators.
  4. We will introduce a concept of critical validators (e.g., foreign key
    integrity) that will run before all other validators.
  5. ValidationContext is now used in a small amount of files, so it will
    be easier to split it into smaller classes.

@aababilov aababilov requested review from barbeau and lionel-nj and removed request for lionel-nj April 21, 2021 12:03
@aababilov aababilov force-pushed the validator-provider branch from cc023a4 to c47f978 Compare April 21, 2021 12:11
@aababilov aababilov requested a review from lionel-nj April 21, 2021 12:12
Copy link
Copy Markdown
Contributor

@lionel-nj lionel-nj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, a few questions inline. As you'll see, my main interrogation resides in the use of DefaultValidatorProvider.

* <p>A {@code ValidatorProvider} is a handy pack of validators passed to different parts of the
* system. Unit tests and users may provide their own implementations of {@code ValidatorProvider}.
*/
public interface ValidatorProvider {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an abstract class? So that clients providing their own set of validation rules would not have to provide an implementation for the methods defined here - but I might have misunderstood the usage of this class.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You see, clients may inherit from DefaultValidatorProvider and override only some methods.

ValidatorProvider as an interface may be fully replaced in a unit tests that does not want to perform any extra validation.

In general, my feeling is that having an interface is cleaner.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clients may inherit from DefaultValidatorProvider and override only some methods.

This is nice! Also could be used in the future to help support profiles bundled with the canonical validator as well, if I understand correctly. It would be nice to have some documentation in a Markdown file for how this works and example use.

@aababilov aababilov force-pushed the validator-provider branch from c47f978 to 02a2fb6 Compare April 21, 2021 22:26
@aababilov
Copy link
Copy Markdown
Collaborator Author

Thanks for review! PTAL.

@aababilov aababilov requested a review from lionel-nj April 21, 2021 22:56
@aababilov
Copy link
Copy Markdown
Collaborator Author

I will add some docs after Lionel merges his #855

We pass a single ValidatorProvider object instead of ValidatorContext
and ValidatorLoader. This allows us to achieve a list of goals.

1. Better modularity and testability. It is possible to inject a custom
   ValidatorProvider in the tests.
2. Clients may provide their own validation for phones, emails etc.
3. We open a way to define custom table header validators.
4. We will introduce a concept of critical validators (e.g., foreign key
   integrity) that will run before all other validators.
5. ValidationContext is now used in a small amount of files, so it will
   be easier to split it into smaller classes.
@aababilov aababilov force-pushed the validator-provider branch from 02a2fb6 to 81d56a9 Compare April 22, 2021 19:17
@aababilov
Copy link
Copy Markdown
Collaborator Author

I resolved merge conflicts.

@aababilov
Copy link
Copy Markdown
Collaborator Author

@barbeau @lionel-nj

How does that look to you guys? That is an important PR to fully switch to the new Validator at Google.

@lionel-nj
Copy link
Copy Markdown
Contributor

I will add some docs after Lionel merges his #855

Currently updating #855 so that we can move forward.

How does that look to you guys? That is an important PR to fully switch to the new Validator at Google.

LGTM! Can't wait to work on profiling using this!

@aababilov
Copy link
Copy Markdown
Collaborator Author

I think that #855 needs more work. Do you mind to merge my PR first? It is a blocker for me.

@aababilov aababilov mentioned this pull request Apr 22, 2021
4 tasks
Copy link
Copy Markdown
Contributor

@lionel-nj lionel-nj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aababilov

@lionel-nj lionel-nj merged commit b2dce65 into MobilityData:master Apr 22, 2021
@aababilov
Copy link
Copy Markdown
Collaborator Author

Thanks, much appreciated!

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

Successfully merging this pull request may close these issues.

3 participants