I am using CodeContracts for the first time, and I have a question regarding this. When I use the ModelState, User, Requestor Responsein my controller code, then Code Contracts states that I need to add Contract.Requires(this.Request != null)in your own code.
Message example:
Warning 1 CodeContracts: There is no precondition in the external visible method. Try adding Contract.Requires (this.ModelState! = Null); to check the parameters
I thought I could remove these messages from code contracts by adding:
[ContractInvariantMethod]
private void ObjectInvariant()
{
Contract.Invariant(this.HttpContext != null);
Contract.Invariant(this.ModelState != null);
Contract.Invariant(this.Request != null);
Contract.Invariant(this.Response != null);
Contract.Invariant(this.RouteData != null);
Contract.Invariant(this.Server != null);
Contract.Invariant(this.Session != null);
Contract.Invariant(this.ViewData != null);
Contract.Invariant(this.User != null);
Contract.Invariant(this.Url != null);
}
In my code. But the ObjectInvariant function is checked at runtime before the Controller.Initialize is called so that all invariants are false.
TL DR
: ?