Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7444081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:26:09+00:00 2026-05-29T11:26:09+00:00

I have several business rules for my FormPartB object that depend on related entities

  • 0

I have several business rules for my FormPartB object that depend on related entities Licensee and FormPartA. I’m new to FluentValidation.

What (I think) I want to do is:

  • Within my FormPartBValidator, get the Licensee and FormPartA entities once, then set up a bunch of rules (i.e. Must() predicates) for FormPartB using values from those related objects.

  • i.e. I dont want to fetch both external entities again within each rule defintion.

I had a couple of thoughts:

(1) Get those entities in the Validator’s constructor, above my RuleFor definitions, then save those entities as private fields,

public PartBValidator()
{
    // Get my external data and save as private fields

    RuleFor...
    RuleFor...
}

or

(2) Get those entities within the call to Validate() then save those entities as private fields:

public override ValidationResult Validate(FormPartB instance)
{
    // Get my external data and save as private fields

    return base.Validate(instance);
}

However

  • In option (1) I can’t seem to access the FormPartB instance

  • In option (2) Validate() doesnt seem to be working the way I thought it would (i.e. doesnt seem to get called on every validation of FormPartB.)

  • And I’m not even sure that “get objects and save as private fields” is the right way to go.

Any advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:26:11+00:00Added an answer on May 29, 2026 at 11:26 am

    I’ve handled this in applications by dependency-injecting a service into the constructor that retrieves the data that validation is dependent on, and it’s worked out quite nicely.

    Here’s an example:

    private readonly IFormService _service;
    
    public PartBValidator(IFormService service)
    {
        _service = service;
    
        var valueICareAbout = _service.GetMeFormAData();
    
        RuleFor...  // uses valueICareAbout
        RuleFor...
    }
    

    If you’re concerned about the performance impact of grabbing that data via the service within the rule definition, you could consider some caching options as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>
I have a WCF web service that exposes several business methods. I also have
I have several interfaces and classes that I have in my business layer project
Our business deals with houses and over the years we have created several business
I have several HTML elements (buttons) that fire the same JQuery AJAX request. When
I have several Delphi programs that maintain connections to a database (some Oracle, some
I have several different numbers in a group that range in sizes and would
I have several classes that implement the same interface. interface IBidManager<E> where E :
I have a server which feeds several applications. Please imagine that I'm a user
I have several questions regarding CI application design. Q. When creating a new form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.