Nov 19, 2008 at 9:19 PM

Welcome to the forum. If anyone has any questions about the library, please feel free to post a question here.

best regards,

Nov 20, 2008 at 4:47 PM
@Chris: The library looks interesting and I'm all for this approach but a few questions:

1. You have to inherit from a base class. I find this to be somewhat intrusive (much like how I keep my domain objects PI). Would it have been a better choice to use a static class (I know, brittle and untestable) or maybe AOP instead?
2. Thoughts around how this plays with the DBC features in .NET 4.0?

Nov 20, 2008 at 9:48 PM
Hi Bil,

Thanks for your interest. Some good questions there. In response...

1) You don't actually need to inherit from ContractBoundObject. This provides a couple of convieniences (particularly if you're using invariants), and makes your code a bit easier to read, but if you read through the implementation, you can see that this actually does call a static class called Contract
for example...

public void Ensure(BaseAssertion assertion) ...only calls ...   Contract.Ensure(assertion);

You can actually call Contract.Ensure, Contract.Require and Contract.Invariant directly, much the same as .NET 4.0's CodeContract class. 

If you are using the ContractDriven library in something like a SingleCall WCF service object, where you have no state, there is no need to use Invariants, and so no real need to use the ContractBoundObject at all. Just Call Contract.Require(assertion) and Contract.Ensure(assertion) at the beginning and end of your methods.

With regard to AOP, this is how the invariant checking in ContractDriven works, the invariant delegates for a class are injected after each method is run. I chose to implement this using the remoting sub-system, rather than a third party framework to keeep the library lightweight and easy to use and avoid un-necessary dependencies and licencing issues. Also, most AOP frameworks use Attributes to define code to be injected. I preferred to keep a consistent syntax for all types of contracts.

2) I have only had a brief look at the new CodeContract class in .NET 4.0. but looks interesting. As with all these things, the are some things that look good and others which I'm not sure about. I will post a comparison to the Wiki when I have examined it more thoroughly. The focus of the ContractDriven.net library is ease-of-use and simplicity. I've always believed that well designed software is about knowing what to leave out rather than what to put in ;-) 

I will be "out-of-internet-range" for the next few days, but if you have any further questions/comments, please get intouch and I'll answer when I get back.

Thanks again for your interest.

best regards,