XAF0001: Implement XPO business class constructors correctly
- 2 minutes to read
Severity: Error
XAF requires that the XPO business object’s constructor should:
- be public,
- take a DevExpress.Xpo.Session object as a parameter,
- pass the DevExpress.Xpo.Session (not the default session) object as an argument to the base class constructor.
Violation of these rules may lead to unexpected results. For example, the New Action may be hidden for this object.
This diagnostic works only for classes derived from the DevExpress.Xpo.PersistentBase class. This diagnostics does not work for abstract classes.
Examples
Invalid Code
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
namespace MySolution.Module.BusinessObjects{
[DefaultClassOptions]
public class ExampleObject1 : BaseObject {
// The constructor must be public
// ExampleObject1(Session session) : base(session) {} // Error: XAF0001
}
// ...
[DefaultClassOptions]
public class ExampleObject2 : BaseObject {
// The constructor must take a Session object as a parameter
// public ExampleObject2(){} // Error: XAF0001
}
// ...
[DefaultClassOptions]
public class ExampleObject3 : BaseObject {
// The constructor must pass a Session object
// as an argument to the base class constructor.
// public ExampleObject3(Session session){} // Error: XAF0001
}
// ...
[DefaultClassOptions]
public class ExampleObject4 : BaseObject {
// The constructor must not pass a DefaultSession object
// as an argument to the base class constructor.
// public ExampleObject4(Session session) : base(Session.DefaultSession) {} // Error: XAF0001
}
// ...
}
Valid Code
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
namespace MySolution.Module.BusinessObjects{
[DefaultClassOptions]
public class ExampleObject1 : BaseObject {
// This constructor meets the requirements
public ExampleObject1(Session session) : base(session) {}
}
// ...
}