private ObjectFactoryInfo CreateObjectFactory(string displayName, FactoryDelegate factoryDelegate, InstanceMode instanceMode) { ObjectFactoryInfo factory = new ObjectFactoryInfo(); factory.FactoryDelegate = factoryDelegate; factory.InstanceMode = instanceMode; factory.DisplayName = displayName; return(factory); }
private T InternalGetObject <T>() { lock (syncRoot) { if (state.TypedObjectFactories.ContainsKey(typeof(T))) { ObjectFactoryInfo config = state.TypedObjectFactories[typeof(T)]; object res = config.FactoryDelegate(); return((T)res); } } throw ExceptionHelper.TypedFactoryNotFoundException(typeof(T)); }
private T InternalGetObject <T>(string factoryId) { lock (syncRoot) { if (state.NamedObjectFactories.ContainsKey(factoryId)) { ObjectFactoryInfo config = state.NamedObjectFactories[factoryId]; try { //get from context cache if (config.InstanceMode == InstanceMode.PerContext && state.namedPerContextObjects.ContainsKey(factoryId)) { return((T)state.namedPerContextObjects[factoryId]); } //get from graph cache if (config.InstanceMode == InstanceMode.PerGraph && state.namedPerGraphObjects.ContainsKey(factoryId)) { return((T)state.namedPerGraphObjects[factoryId]); } //get from thread cache if (config.InstanceMode == InstanceMode.PerThread && state.namedPerThreadObjects.ContainsKey(factoryId)) { return((T)state.namedPerThreadObjects[factoryId]); } object res = config.FactoryDelegate(); if (res is IRunnable) { RunnableEngine.RunRunnable(res as IRunnable); } //add to context cache if (config.InstanceMode == InstanceMode.PerContext) { state.namedPerContextObjects.Add(factoryId, res); } //add to graph cache if (config.InstanceMode == InstanceMode.PerGraph) { state.namedPerGraphObjects.Add(factoryId, res); } //add to thread cache if (config.InstanceMode == InstanceMode.PerThread) { state.namedPerThreadObjects.Add(factoryId, res); } return((T)res); } finally { } } } throw ExceptionHelper.NamedFactoryNotFoundException(factoryId); }
private void RegisterObjectFactoryMethod(string factoryId, FactoryDelegate factoryDelegate, InstanceMode instanceMode) { ObjectFactoryInfo factory = CreateObjectFactory(factoryId, factoryDelegate, instanceMode); state.NamedObjectFactories.Add(factoryId, factory); }
private void RegisterObjectFactoryMethod(Type objectType, FactoryDelegate factoryDelegate, InstanceMode instanceMode) { ObjectFactoryInfo factory = CreateObjectFactory("DefaultFor:" + objectType.Name, factoryDelegate, instanceMode); state.TypedObjectFactories.Add(objectType, factory); }