Is there some way to assign the ObjectFactory of a class at runtime?

Is there some way to assign the ObjectFactory of a class at runtime?

Old forum URL: forums.lhotka.net/forums/t/7841.aspx


Dane posted on Wednesday, October 21, 2009

I'm playing around with the idea of data source agnosticism.  Different data sources obviously require different data access code.  At runtime it will be known which single set of data access code should be utilized but I don't see a way to specify the ObjectFactory for a class at runtime.  Right now I'm using a bridge pattern to create an instance of the correct ObjectFactory from the "primary"  ObjectFactory that is specified by the attribute on the related business class but that "primary" ObjectFactory really becomes nothing but a pass-through.  If there was some way to specify the correct ObjectFactory at runtime I could simply do away with the one that is currently the "primary".

JonnyBee replied on Thursday, October 22, 2009

Hi,

You should look at implementing your own ObjectFactoryLoader. You may look at the ProjectTracker sample from Csla 3.7.1 for N2 that allows you to configure one of  2 independent Factories (Subsonic or raw ADO.NET).

Dane replied on Thursday, October 22, 2009

Excellent!  That's exactly what I was looking for and worked like a charm.  Thanks.

Copyright (c) Marimer LLC