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.
Latest Comments