This project is read-only.

Create a Wrapper

May 14, 2013 at 3:36 PM

I'd like to thank you for a great library. I have an idea of creating a wrapper for this library. I have one question though, how can we achieve something like this? I managed to supply the expression as a parameter to the setupclass, but I need somehow to invoke a certain method, say "MustNotBeNullOrEmpty". I was thinking of reflection but I failed.

Do you have any ideas?
May 14, 2013 at 11:50 PM

My question would be: why are you trying wrap for the whole library?

"MustNotBeNullOrEmpty" and like functions, are already wrappers around the RulesEngine object, they are there to 'wrap' the registration of rule invokers. when I understand 'Wrapping' I think facades, which would involve you creating a IValidate interface in code.... then with ServiceLocation pattern, you can do something like that in your code:

var validator = ServiceLocator.Resolve<IValidate>()
var validationResult = validator.Validate(myObject).

By doing that (also wrap the ValidationResult), you can use RulesEngine in your codebase without creating dependencies on the framework everywhere. In fact once this is in place, you could safely replace RulesEngine with another framework as long as you create a Wrapper that implements your IValidate interface...

Remember, setting up your rules is a one-time thing. You can do all that then registering IValidate to your ServiceLocator - that would be the only code in your codebase that is strongly dependant on the RulesEngine framework.

Hope this helps.