Below you will find the description of the minimal changes to XPO sources to make the ORM+IoC series samples work. Obviously, I’m quite limited with that, since these sources are commercial.
That’s the new method that we have to add to ReflectionDictionary to make it recognize out interfaces:
public void AddClassInfo(Type service, XPClassInfo implementation)
{
classesByType.Add(service, implementation);
}
Or one could just add method that looks up existing type registration and re-registers it as service type, while hiding the ClassInfo specifics.
The changes, that differ FireSession (and logically linked classes) from normal Session, revolve around the delivery of the _resolver delegate from the FireSession Constructor to this method inside ObjectLoader:
void CreateTypedObject(object id, XPClassInfo classInfo) {
theObject = null == _resolver ?
classInfo.CreateObject(loader.Session) :
_resolver(classInfo.ClassType);
cache.Add(classObjects, theObject, id);
}
The _resolver delegate is a simple lambda passed down from the IoC:
private Func<Type, object> _resolver;
...
// register FireSession with the default data layer
builder.Register<Session>(
c => new FireSession(type => c.Resolve(type))).ContainerScoped();
Note: these 30min hacks are neither stable nor intended for production. It would require at least XPO unit-test suite and IoC+ORM functionality/integration tests to stabilize them with all the required usage scenarios. And that’s out of the scope of the current research.
In my next article I’ll get to the topic of the efficient unit-testing of decoupled components with the MockContainer. That’s where we left the xLim 2 series.

Hi Rinat,
There is no need to change XPO source, because XPO already provides methods to help you with your task. Below is the list of classes and their members, at which we advise you to take look.
XPDictionary.QueryClassInfo
ReflectionDictionary.ResolveClassInfoByName
ReflectionDictionary.ResolveClassInfoByType
XPDictionary.CanGetClassInfoByType
XPClassInfo.CreateObjectInstance
XPBaseObject..ctor(Session, XPClassInfo)
Thank you,
Nick
Developer Express Support
Nick,
Thank you for the comment. Yes, I’ve seen them all.
But, as you can see from this ORM+IOC series, queries ask the XPO (via IoC) not for the specific BO (i.e. Account), but for the IAccount interface behind it, since we are completely decoupling from the implementation.
I could not find any simple solution to make the dictionary recognize the Account when it is being asked for IAccount, so I had to register the ClassInfo manually one more time with the interface.
Did I miss something?
Best regards,
Rinat
XPO developers told me to recommend to look at:
XPDictionary.CanGetClassInfoByType
XPDictionary.QueryClassInfo
XPClassInfo.CreateObjectInstance
I did not check myself - just a note.
Oops, did not read the comment above :-)
Rinat,
You can create a custom dictionary class and override its XPDictionary.CanGetClassInfoByType virtual method to return a persistent class info for a given interface type. In addition, your base persistent object class must provide a constructor with the Session and XPClassInfo parameters, so that XPO can create an instance of it.
If my suggestion doesn’t work for you, please submit your sample project to our Support Center. We’ll look for a solution.
Nick,
1. Thank you for suggestion, but do not worry about this. I’m not using this approach anywhere close to production yet (may be there will be something more flexible and simple). Besides, adding tiny method to the ReflectionDictionary was not hard at all.
If you want to implement this in the XPO sources, then you could simply add some “void RegisterAs{T,I}() where T:I” method, that would ask for the XPClassInfo for T and reregister it as I.
However, it would be nice, if the XPO team could remove self-locks from the Session code. It hurts to see these booby traps around.
2. If you check out the ORM+IoC series, then you would notice that I’m creating objects outside the XPO (even if they are requested by the ObjectLoader) just to have these instances injected with the dependencies by IoC (Session happens to get in there same way as well)
Best regards,
Rinat
Roman,
Thank you for dropping a line here.
BTW, I apologize for pushing hard on the XAF team.
I’m trying to restrain myself now))
Best regards,
Rinat
Rinat,
I was joking, don’t worry - we are open for constructive critic and we are listening.
Roman