background preloader

Validation

Facebook Twitter

Technical Jargon. In my recent FluentValidation presentation I mentioned that if you’re going to be using FluentValidation with ASP.NET MVC then you should probably be using an Inversion of Control container rather than using the AttributedValidatorFactory. What is a Validator Factory? A validator factory is a class responsible for creating validator instances. The IValidatorFactory interface looks like this: public interface IValidatorFactory { IValidator<T> GetValidator<T>(); IValidator GetValidator(Type type);} The interface has two methods – one generic, one not. Creating your own Validator Factory To create your own Validator Factory you can either implement IValidatorFactory directly, or inherit from the ValidatorFactoryBase class (which does some of the work for you). Firstly, you’ll need to register your validator types with StructureMap: Here I am configuring StructureMap using a custom Registry.

Now, you can write a custom ValidatorFactory that leverages StructureMap to instantiate the validator: Fluent Validation for .NET. Validation Toolkit for WPF & Silverlight. .NET Junkie - Integrating Enterprise Library Validation Application Block with LINQ to SQL and Entity Framework Part 2: Using context within custom validators. The Enterprise Library Validation Application Block, or VAB for short, is great for those simple validations like checking for null strings or checking for a number to fall within a specified range.

However, I bet you do, like me, far more complex validations in your enterprise applications. It's not uncommon for me in having to query the database during validation. Let's make it clear, in the context of O/RM frameworks, those types of validations tend to get pretty complicated very quickly. This is because you will have to deal with both in-memory state and database state and perhaps even deal with the possibility of multiple users changing data at the same time, while preventing invalid state in the database. Nevertheless, when the enterprise architecture prescribes the use of an O/RM and VAB, having the ability to use your O/RM framework within your custom validators might simply be necessarily. using System;using System.Collections.Specialized; using System; if (currentContext !

Building DSLs on CLR and DLR (.NET) Tulip Rules - Download: Proof of Concept. The Proof of Concept includes the Tulip Engine and a hand-crafted implementation of the classic Miss Manners rule set. Miss Manners is often used for comparative benchmark testing. However, it does not represent a real-world implementation. It was written, many years ago, by Daniel Miranker as part of a small suite of test rule sets to aid comparison between different implementations of OPS5. It solves a very simple constraint problem. Given a pool of potential guests, find a seating arrangement for a given number of seats in which gender alternates around the table (male/female) and where each guest shares at least one hobby with the person next to them on each side. The test contains eight rules. Manners is generally run for 16, 32, 64 and 128 seats. This version of the test was written as a proof of concept, and used to undertake preliminary optimization of the engine.

The MannersTest application is a console application. (batch n) ...where n is the number of seats. Enjoy! PS. Drools. 1.6. The Drools Rule Engine. Drools is split into two main parts: Authoring and Runtime. The authoring process involves the creation of DRL or XML files for rules which are fed into a parser - defined by an Antlr 3 grammer. The parser checks for correctly formed grammer and produces an intermediate structure for the "descr"; where the "descr" indicates the AST that "describes" the rules. The AST is then passed to the Package Builder which produces Packages. Package Builder also undertakes any code generation and compilation that is necessary for the creation of the Pacakge.

A Packge object is self contained and deployeable, in that it's a serialized object consisting of one or more rules. Figure 1.10. A RuleBase is a runtime component which consists of one or more Packages. Figure 1.11. Figure 1.12. Three classes are used for authoring: DrlParser, XmlParser and PackageBuilder. Example 1.1. PackagBuilder is configurable using PackageBuilderConfiguration. Example 1.2. Example 1.3. Figure 1.13. Figure 1.15. 1.6.4.5. Loading and managing rules dynamically from a database - Drools. Skip to end of metadata Go to start of metadata Thanks to Sujit Pal for this article (sujit.pal@comcast.net) and the contribution. (Note that this is being adapted into a rule repository for Drools 3, adding in versioning, history, searching etc.) Why use Rules - Allows us to abstract changeable business logic out of an application. Changing application behavior by changing the rules is faster and cheaper than having to make changes in the code to accomodate the new rules Why put Rules in a Database - Putting rules into the database allows us to change business rules while the application is running.

The application is divided into two main parts - the Java database interface and the web interface. The Java interface can be used to programmatically manipulate rulesets in the database and to execute named rulesets. The high level architecture for the database interface is shown below (click on images to enlarge): The rulesets need a database to store them. Web interface configuration. Review – InRule: A Business Rules Management System for .NET. I don’t usually do a product profile unless I either really like the product and use it myself, or I’m genuinely curious about the product and what it can do for me.

While I haven’t used InRule before, it does fit the latter of those criteria because of my interest in similar products I have used in the past. A Quick Intro to my Life in Rules… Flash back to my college years (when 5.25” floppies were king) and you’d see a young guy in an Artificial Intelligence class learning about a Knowledge Based Expert System known as CLIPS (C-Language Integrated Production System) which was developed by NASA for rules processing. This class fascinated me, and when I got out of college I started my first job in St. Here I honed my C++ skills, and also worked more with a retail version of the CLIPS language that ran on the AIX platform for handling the aforementioned RBOC’s Order Service. From Expert Systems to Business Rules Management Systems InRule – A .NET Business Rules Mangement System 3: Unknown,

Entity validation with visitors and extension methods. On the Yahoo ALT.NET group, an interesting conversation sprung up around the topic of validation. Entity validation can be a tricky beast, as validation rules typically depend on the context of the operation (persistence, business rules, etc.). In complex scenarios, validation usually winds up using the Visitor pattern, but that pattern can be slightly convoluted to use from client code.

With extension methods in C# 3.0, the Visitor pattern can be made a little easier. Some simple validation In our fictional e-commerce application, we have a simple Order object. Right now, all it contains are an identifier and the customer’s name that placed the order: public class Order { public int Id { get; set; } public string Customer { get; set; } } Nothing too fancy, but now the business owner comes along and requests some validation rules. The other requirement is to have a list of broken rules in case the object isn’t valid, so the end user can fix any issues. Using validators A generic solution. InRule Technology. Fluent Validation for .NET. Mix: Getting my head around Oslo, M and MGrammar. .net - What technology to use in creating DSL for rules engine.