[Coldbox 4.1] validatemodel

I have injected the module in my baseservice that all my other services extend like so
property name=“ValidatorService” inject=“provider:ValidationManager@cbvalidation”; on a side note, I don’t understand why I have to use the provider namespace but it does not work without it.

but when I call prc.validationResults = NotificationService.validateModel( Notification ); in my handler I get the following error.

The method validateModel was not found in component G:\apps\lib\frameworks\coldbox-4.1.0\modules\cbvalidation\models\ValidationManager.cfc.

The error message indicates that the variable NotificationService is empty.

The correct syntax for what you want to do is.

property name=“ValidatorService” inject=“model:ValidationManager@cbvalidation”;

However, I do recall you had some issues about when your modules are loaded and injected, my guess is that the services are not instantiated when the module is.

I am not following you on the error message indication, the error message is saying that it can’t find the validatemodel method in G:\apps\lib\frameworks\coldbox-4.1.0\modules\cbvalidation\models\ValidationManager.cfc. correct?

Looks like you are injecting a variable called ValidationService but then calling NotificationService.validateModel()

prc.validationResults = NotificationService.validateModel( Notification );

yes I am injecting that on the base service which all of my other services including notification service are extending.

try this

writeDump(NotificationService); abort;

before the call and you will see what I mean.

I am just not following you, here is what I get when I dump Notification service, its not empty, and has the validatorservice as a property

Capture.PNG

I think Tim hit the nail on the head, but if you open the methods up, I am guessing that the method you want is not part of the object.

As Time pointed out your saying you have this

property name=“ValidatorService” inject=“provider:ValidationManager@cbvalidation”;

and that your reference it like this

prc.validationResults = NotificationService.validateModel( Notification );

But from the Dump you posted I am think you need something like this

prc.validationResults = NotificationService.ValidationService.validateModel( Notification );

or this if you have setters enabled.

prc.validationResults = NotificationService.getValidationService().validateModel( Notification );

I thought by dumping out the object you could at least open it up and just double check that what you expect in the methods, is actually there.

Thanks, I ended up just injecting cbvalidator in the wirebox config and removing it from the base service all together. and then just calling

prc.validationResults = validateModel( Notification );

Turns out that I needed some custom stuff that we had added to format data before it called the main validatemodel method. so the above solution would not work. I update our override method to call ValidatorService.validate( argumentCollection=arguments ); for some reason it could no longer find the validatemodel() method even though it appears to be included in the mixin.