Exemple #1
0
        public static void RegisterSingleton <T>(IConfigurableListableObjectFactory objectFactory) where T : class, new()
        {
            Type type     = typeof(T);
            var  instance = new T();

            objectFactory.RegisterSingleton(type.FullName, instance);
        }
        private static void RegisterObject(string objectName, object obj, IObjectFactory objectFactory)
        {
            AssertUtils.ArgumentNotNull(objectName, "object name must not be null");
            IConfigurableListableObjectFactory configurableListableObjectFactory = null;

            if (objectFactory is IConfigurableListableObjectFactory)
            {
                configurableListableObjectFactory = (IConfigurableListableObjectFactory)objectFactory;
            }
            else if (objectFactory is GenericApplicationContext)
            {
                configurableListableObjectFactory = ((GenericApplicationContext)objectFactory).ObjectFactory;
            }
            if (obj is IObjectNameAware)
            {
                ((IObjectNameAware)obj).ObjectName = objectName;
            }
            if (obj is IObjectFactoryAware)
            {
                ((IObjectFactoryAware)obj).ObjectFactory = objectFactory;
            }
            if (obj is IInitializingObject)
            {
                try
                {
                    ((IInitializingObject)obj).AfterPropertiesSet();
                }
                catch (Exception ex)
                {
                    throw new FatalObjectException("failed to register bean with test context", ex);
                }
            }
            if (configurableListableObjectFactory == null)
            {
                throw new ArgumentException("configurableListableObjectFactory must not be null");
            }

            configurableListableObjectFactory.RegisterSingleton(objectName, obj);
        }
Exemple #3
0
 public static void RegisterInstance <TSerivice>(this IConfigurableListableObjectFactory confObjFactory, TSerivice instance)
 {
     confObjFactory.RegisterSingleton(typeof(TSerivice).FullName, instance);
 }