Example #1
0
        public void Connect(string id, Type classType, Type serviceType, ComponentLifestyle lifestyle)
        {
            Hashtable extendingProperties = new Hashtable();

            extendingProperties[typeof(ComponentLifestyle)] = lifestyle;

            switch (lifestyle)
            {
            case ComponentLifestyle.Singleton:
                Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties);
                break;

            case ComponentLifestyle.Transient:
                Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties);
                break;

            case ComponentLifestyle.DependencyInjectionOnly:
                Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties);
                break;

            case ComponentLifestyle.Undefined:
                Kernel.AddComponent(id, serviceType, classType);
                break;

            default:
                throw new ArgumentException("ComponentLifestyle 参数无效: " + lifestyle);
            }
        }
Example #2
0
        private void ConfigureAndAddContainer()
        {
            IConfiguration config = FacilityConfig.Children["container"];

            IDictionary properties = new Hashtable();

            String compKey = config.Attributes[IdKey];

            properties.Add(IdKey, compKey);
            properties.Add(DatabaseFileKey, config.Attributes[DatabaseFileKey]);

            properties.Add(ExceptionsOnNotStorableKey, Convert.ToBoolean(config.Attributes[ExceptionsOnNotStorableKey]));

            if (config.Attributes[CallConstructorsKey] != null)
            {
                properties.Add(CallConstructorsKey, Convert.ToBoolean(config.Attributes[CallConstructorsKey]));
            }

            if (config.Attributes[ActivationDepth] != null)
            {
                properties.Add(ActivationDepth, Convert.ToInt32(config.Attributes[ActivationDepth]));
            }

            if (config.Attributes[UpdateDepth] != null)
            {
                properties.Add(UpdateDepth, Convert.ToInt32(config.Attributes[UpdateDepth]));
            }

            if (config.Attributes[HostNameKey] != null)
            {
                properties.Add(HostNameKey, config.Attributes[HostNameKey]);
                properties.Add(RemotePortKey, Convert.ToInt32(config.Attributes[RemotePortKey]));
                properties.Add(UserKey, config.Attributes[UserKey]);
                properties.Add(PasswordKey, config.Attributes[PasswordKey]);
            }

            Kernel.AddComponentWithExtendedProperties(compKey, typeof(ObjectContainer), typeof(ObjectContainer), properties);
        }