Using the WebConfig for business rules container

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm wanting to use a config file to hold groups of business rules and am
thinking of using the webconfig file for this so the first question I need
to ask is: Is the webconfig file the appropriate place to do this or do I
need to create a custom config file?

The next question is how can I nest elements to contain the various
groupings and logic? for example I'm using the webconfig file already for
some very basic stuff line holding constant values the applications can use
for logic like this:

<appSettings>
<add key="ContestEndDate" value="11/08/2023 11:59:59 PM" />
<add key="EmailServer" value="192.168.100.10" />
<add key="EmailFrom" value="(e-mail address removed)" />
<add key="EmailEnabled" value="true" />
<add key="LoggingEnabled" value="true" />
<add key="RequireSSL" value="false" />
<add key="DiscountMarkForShipping" value="60" />
<add key="RunFrom" value="TestMachine_TestDB" />
<add key="StandardCacheTime" value="30" />
</appSettings>

But what I want to start doing is add an element that would contain my rules
like this

<appSettings>
<CustomAppRules>
<Rule1 someAttribute="xyz">
<SomeMoreStuff/>
</Rule1>
<Rule2>
<Condition ix="1" val="123">
<Action val="blablabla"/>
</Condition>
<Condition ix="2" val="456">
<Action val="blablabla"/>
</Condition>
</Rule2>
<CustomAppRules>
</appSettings>

Is this possible and if so, how would I access these rules and there
conditions? To access the regular stuff in the webconfig I call their
values like this:

Dim iDiscountMark As Int16 =
CType(System.Configuration.ConfigurationSettings.AppSettings("DiscountMarkFo
rShipping"), Int16)

Can I get some advice on this and also some reference material in general
about building rules engines using config files?

Thanks.
 
You'd probably be better off creating a separate business rules XML file.
Then you could read and parse it using the XMLDocument or other class.

In fact, for a quick solution, you could store the rules as an XML dataset
and just load the data to the dataset when needed.

<?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <Table>
<OrderID>10248</OrderID>
<CustomerID>VINET</CustomerID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00.0000000-04:00</OrderDate>
<RequiredDate>1996-08-01T00:00:00.0000000-04:00</RequiredDate>
<ShippedDate>1996-07-16T00:00:00.0000000-04:00</ShippedDate>
<ShipVia>3</ShipVia>
<Freight>32.3800</Freight>
<ShipName>Vins et alcools Chevalier</ShipName>
<ShipAddress>59 rue de l'Abbaye</ShipAddress>
<ShipCity>Reims</ShipCity>
<ShipPostalCode>51100</ShipPostalCode>
<ShipCountry>France</ShipCountry>
</Table>
</NewDataSet>
 
Hi Ken,

Thanks for your reply.

Hi Moondaddy,

I agree with Ken 's suggestion that it'll be better to use a custom xml
configure file to contain such complex infos(such as nested xml elements).
And in addition to the "XmlDocument" or other generic xml related classes
in dotnet, I think you can also have a look at the "Xmlserialization" in
dotnet which can help us to serialize some certain custom class into xml
files and rebuild instances from xml files(documents). Here are some
weblinks of the reference in MSDN:

#XML Serialization in the .NET Framework
http://msdn.microsoft.com/library/en-us/dnexxml/html/xml01202003.asp?frame=t
rue

#Introducing XML Serialization
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconintroducingxmlseri
alization.asp?frame=true''

#Examples of XML Serialization
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconanexampleofxmlseri
alizationwithxmlserializer.asp?frame=true

Hope helpful.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

-------------------------------------------------------------------------
 
Back
Top