1
I Use This!
Activity Not Available

News

Posted about 11 years ago by xdzgor
Of course, thank you, works like a charm.
Posted about 11 years ago by JeremyS
Hi Olivier I can't really answer the question "is this architecture correct" as this is quite subjective and really depends on the project you're working on, so without knowing more details of the project and the problem you're trying to solve ... [More] , it's very hard to say. I don't think there's anything wrong with this approach per-se, but it does seem rather complex. This might be fine for your application, but it might also be overkill. For example, a project that is only going to have a short lifetime probably doesn't need an architecture this complex. I wouldn't tend to worry about questions such as "is it good practice to inject into an extension method", but instead ask yourself questions such as "does this actually help solve the business problem, or is it unnecessarily complex?" and "Will it be easily understood by the other developers on the team (and future developers who come along)?" Sorry I can't be of more help! Jeremy [Less]
Posted about 11 years ago by JeremyS
Hi You can use a Must rule to do this - the Must method takes a delegate where you can perform custom logic: class MyValidator:AbstractValidator<Parent> { public MyValidator() { RuleFor(x => x.Children).Must(HaveValidChildren); } ... [More] private bool HaveValidChildren(Parent parent, Child[] children) { // loop over each child and compare to parent as necessary. } } Hope this helps [Less]
Posted about 11 years ago by olivier5741
Hi, I'm using PRISM (WPF client) and would like to define custom property validators (FluentValidation) on module level and being abled to use them in other modules (using MEF dependency injection to avoid project cross-reference). This is the ... [More] architecture is was thinking about : BOB module references Infrastructure (to be able to use BOB PropertyValidatorExtensions) DossierUniqueName : PropertyValidator (to provide client-side database check on unique name) is exported through MEF REF module references Infrastructure ServiceInDivision : PropertyValidator (to provide client-side database check if a service belongs to a given division ) is exported through MEF Infrastructure project BOB PropertyValidatorExtensions [static class] DossierUniqueName property validator is discovered through dependency-injection (serviceLocator) REF PropertyValidatorExtensions [static class] ServiceInDivision property validator is discovered through dependency-injection (serviceLocator) Is this architecture correct ? Is there another way to sustain this scenario by using FluentValidation Validator Factory ? Is it good practice to inject object into extension method ? Regards, Olivier [Less]
Posted about 11 years ago by xdzgor
Hi - how can I formulate a rule which loops over each "child" in an array, and checks that certain properties in each child are the same as corresponding properties in the "parent"? For example, I have class Parent { string Path; string ... [More] Category; string Title; Child[] Children; } class Child { string Path; string Category; string Title; } The "Path" and "Category" properties in each Child must be the same as the Path and Category properties in the Parent. Note that I also cannot be sure that each position in the Child-array has a Child object - an array position may hold "null" for example, and I want to avoid NullReferenceExceptions. Thanks for any advice. [Less]
Posted about 11 years ago by JeremyS
I don't think this is really related to FluentValidation - my understanding of WebApi is pretty limited, but I believe that the Formatter handles this internally. If the field is present but empty in the request, then nothing will be passed to the ... [More] model and so the property will remain null (or stay as it's default value if it's a non-nullable value type). So if you want to change this behaviour, I believe you'd need to write your own formatter. Jeremy [Less]
Posted about 11 years ago by TrentArwine
I'm using fluent validation with WebApi. One of my non-required fields is "salary." However, even though it is not a required field the vendor always sends the field even if it is empty. For example: ... [More] <Employee><FirstName>Joe</FirstName><LastName>Bravo</LastName<Salary></Salary>. In my model, salary is a nullable double. I would like to allow the empty value to be passed in and during validation, handle it (perhaps change the empty string to a 0). Is this possible with Fluent Validation? If so, how? [Less]
Posted about 11 years ago by MartinJ87
Awesome, thank you Jeremy! :-)
Posted about 11 years ago by nportelli
Huh no kidding. I guess I've never ran into that before. Ok nevermind.
Posted about 11 years ago by JeremyS
Yep, that's a built in message that MVC generates from within its model-binding infrastructure and can't be turned off. Very annoying. Basically you either need to: 1) Make the property nullable 2) Ensure that your form submits a value for that field, even if it's 0 (for example, in a hidden field)