Example #1
0
        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));
        }
Example #2
0
        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);
        }