示例#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);
            }
        }
示例#2
0
 public Registration(
     IComponentDescriptor descriptor,
     IComponentActivator activator,
     IEnumerable <IParameter> parameters,
     ComponentLifestyle lifestyle)
 {
     _descriptor = Enforce.ArgumentNotNull(descriptor, "descriptor");
     _activator  = Enforce.ArgumentNotNull(activator, "activator");
     _lifestyle  = lifestyle;
     _scope      = scope.InstanceScopeFactory.ToScope(lifestyle);
 }
示例#3
0
        public static bool IsComponentLifestyle(this Type type, ComponentLifestyle lifestyle)
        {
            var a = type.GetCustomAttributes(typeof(ComponentAttribute), true)
                    .OfType <ComponentAttribute>()
                    .FirstOrDefault();

            if (a == null)
            {
                return(false);
            }

            return(a.Lifestyle == lifestyle);
        }
        public static IScope ToScope(ComponentLifestyle lifestyle)
        {
            switch (lifestyle)
            {
            case ComponentLifestyle.Transient:
                return(new TransientScope());

            case ComponentLifestyle.Singleton:
                return(new SingletonScope());

            default:
                throw new NotSupportedException(string.Format("生命周期 '{0}' 不可识别.", lifestyle));
            }
        }
示例#5
0
        public Descriptor(string id
                          , IEnumerable <Type> services
                          , Type implementationType
                          , ComponentLifestyle lifestyle
                          , int level
                          , IEnumerable <IParameter> parameters
                          , IProperties extendedProperties)
        {
            _id = Enforce.ArgumentNotNullOrEmpty(id, "id");
            _implementationType = Enforce.ArgumentNotNull(implementationType, "implementationType");

            _services           = services;
            _lifestyle          = lifestyle;
            _level              = level;
            _parameters         = parameters;
            _extendedProperties = extendedProperties;
        }
示例#6
0
        public void Register(Type implementationType, ComponentLifestyle lifestyle, params Type[] asType)
        {
            var builder = _containerBuilder.RegisterType(implementationType);

            if (asType.Length != 0)
            {
                builder = builder.As(asType);
            }

            if (lifestyle == ComponentLifestyle.PerRequest)
            {
                builder.InstancePerLifetimeScope();
            }
            else if (lifestyle == ComponentLifestyle.Singleton)
            {
                builder.SingleInstance();
            }
        }
示例#7
0
 public void RegisterAs <T, TAs>(ComponentLifestyle lifestyle) where T : TAs
 {
     if (lifestyle == ComponentLifestyle.PerRequest)
     {
         _containerBuilder.RegisterType <T>().As <TAs>().InstancePerLifetimeScope().PropertiesAutowired(PropertyWiringOptions.PreserveSetValues);
     }
     else if (lifestyle == ComponentLifestyle.Singleton)
     {
         _containerBuilder.RegisterType <T>().As <TAs>().SingleInstance().PropertiesAutowired(PropertyWiringOptions.PreserveSetValues);
     }
     else if (lifestyle == ComponentLifestyle.Transient)
     {
         _containerBuilder.RegisterType <T>().As <TAs>().PropertiesAutowired(PropertyWiringOptions.PreserveSetValues);
     }
     else
     {
         throw new ArgumentOutOfRangeException(nameof(lifestyle), lifestyle, null);
     }
 }
示例#8
0
        private LifestyleType GetLifestyleType(ComponentLifestyle componentLifestyle)
        {
            var lifestyleType = (LifestyleType)Enum.Parse(typeof(LifestyleType), componentLifestyle.ToString(), true);

            return(lifestyleType);
        }
示例#9
0
 public void Register <T, TAs>(ComponentLifestyle lifestyle) where T : TAs
 {
     Register(typeof(T), lifestyle, new[] { typeof(TAs) });
 }
示例#10
0
 public ComponentAttribute(ComponentLifestyle lifestyle, bool start)
 {
     Lifestyle = lifestyle;
     Start     = start;
 }
示例#11
0
 public ComponentAttribute(ComponentLifestyle lifestyle)
     : this(lifestyle, false)
 {
 }
示例#12
0
 public ComponentAttribute(ComponentLifestyle lifestyle = ComponentLifestyle.Transient)
 {
     _lifestyle = lifestyle;
 }
示例#13
0
 public ComponentAttribute(ComponentLifestyle lifestyle) : this(lifestyle, false)
 {
 }
示例#14
0
 public void Connect(string id, IEnumerable <Type> serviceTypes, Type classType, ComponentLifestyle lifestyle, IEnumerable <IParameter> parameters, IProperties properties)
 {
     throw new NotImplementedException();
 }
示例#15
0
 public void Connect(string id, Type classType, Type serviceType, ComponentLifestyle lifestyle)
 {
     _adapter.Connect(id, classType, serviceType, lifestyle);
 }
示例#16
0
 public void Register <T>(ComponentLifestyle lifestyle)
 {
     Register(typeof(T), lifestyle);
 }
示例#17
0
        void IContainer.RegisterComponent(string key, Type serviceType, Type classType, ComponentLifestyle componentLifestyle)
        {
            LifestyleType lifestyleType = GetLifestyleType(componentLifestyle);

            _container.AddComponentLifeStyle(key, serviceType, classType, lifestyleType);
        }
示例#18
0
 public ComponentAttribute(ComponentLifestyle lifestyle)
 {
     Lifestyle = lifestyle;
 }
示例#19
0
 public ComponentAttribute(ComponentLifestyle lifestyle, bool start)
 {
     Lifestyle = lifestyle;
     Start = start;
 }
示例#20
0
 public ComponentAttribute(ComponentLifestyle lifestyle = ComponentLifestyle.Transient)
 {
     _lifestyle = lifestyle;
 }
示例#21
0
 public void Register(Type implementationType, ComponentLifestyle lifestyle)
 {
     Register(implementationType, lifestyle, new Type[] { });
 }
示例#22
0
 public void RegisterAs <T, TAs>(ComponentLifestyle lifestyle) where T : TAs
 {
     _dependencyContainer.RegisterAs <T, TAs>(lifestyle);
 }
示例#23
0
 public virtual TSyntax WithLifestyle(ComponentLifestyle lifestyle)
 {
     _lifestyle = lifestyle;
     return(Syntax);
 }
示例#24
0
 public void Register(Type implementationType, ComponentLifestyle lifestyle, params Type[] asType)
 {
     _dependencyContainer.Register(implementationType, lifestyle, asType);
     RegisteredInterfaces.AddRange(asType);
 }