private static T New <T>(Type objType, IChoCustomObjectFactory customObjectFactory) { if (customObjectFactory == null) { return((T)ChoType.CreateInstance(objType)); } //return (T)ChoRealProxy.GetProxy(ChoType.CreateInstance(objType)); else { return((T)customObjectFactory.CreateInstance(objType)); } }
public ChoObjectFactoryAttribute(IChoCustomObjectFactory customObjectFactory) { _customObjectFactory = customObjectFactory; }
private static object New(Type objType, IChoCustomObjectFactory customObjectFactory) { return(New <object>(objType, customObjectFactory)); }
internal static T CreateInstance <T>(Type objType, ChoObjectConstructionType defaultObjectConstructionType, bool beforeFieldInit, out Exception exception) { exception = null; ChoGuard.ArgumentNotNull(objType, "objType"); T instance = default(T); ChoObjectConstructionType objectConstructionType = defaultObjectConstructionType; if (IsConstructing(objType)) { instance = New <T>(objType, null); if (instance != null) { ChoObjectInitializer.Initialize(instance, beforeFieldInit); } } else { try { _globalObjectBuildStateCache[objType] = ObjectBuildState.Constructing; IChoCustomObjectFactory customObjectFactory = null; ChoObjectFactoryAttribute objectFactoryAttribute = ChoType.GetAttribute(objType, typeof(ChoObjectFactoryAttribute)) as ChoObjectFactoryAttribute; if (objectFactoryAttribute != null) { objectConstructionType = objectFactoryAttribute.ObjectConstructionType; customObjectFactory = objectFactoryAttribute.CustomObjectFactory; } switch (objectConstructionType) { case ChoObjectConstructionType.Singleton: //lock (_globalObjectCache.SyncRoot) //{ if (_globalObjectCache.ContainsKey(objType)) { return((T)_globalObjectCache[objType]); } else { instance = New <T>(objType, customObjectFactory); _globalObjectCache[objType] = instance; } //} break; default: instance = New <T>(objType, customObjectFactory); break; } if (instance != null) { try { ChoObjectInitializer.Initialize(instance, beforeFieldInit); } catch (TypeInitializationException) { throw; } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { exception = ex; } } } finally { _globalObjectBuildStateCache[objType] = ObjectBuildState.Constructed; } } return(instance); }