public InterceptionBehaviorMap Mapping(Type serviceType, params Type[] behaviorTypes)
        {
            serviceType.NotNull("serviceType");
            serviceType.NotNull("behaviorType");

            if (behaviorTypes.Length <= 0) {
                //throw new ArgumentException("长度必须大于零。", "behaviorTypes");
                return this;
            }

            behaviorTypes.ForEach(behaviorType => {
                if (!typeof(IInterceptionBehavior).IsAssignableFrom(behaviorType)) {
                    throw new ArgumentException(string.Format("Type {0} no inheritance IInterceptionBehavior.", behaviorType.FullName));
                }
            });

            int length = behaviorTypes.Length;
            int[] typeCodes = new int[length];
            int index = 0;
            while (index < length) {
                typeCodes[index] = RegisterType(behaviorTypes[index++]);
            }

            _behaviorMap.Add(serviceType, typeCodes);

            return this;
        }
        /// <summary>
        /// Add a Type with alias key to the archetype cache
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="instanceType"></param>
        public static void AddTypeByAlias(string alias, Type instanceType)
        {
            alias = alias.NotNull();
            instanceType = instanceType.NotNull();

            _archetypeCache.TryAdd(alias, instanceType);
        }
 /// <summary>
 /// Creates a new instance of a <see cref="T:ILoggingProvider"/> of the type <typeparamref name="t"/>.
 /// </summary>
 /// <param name="t"><see cref="T:Type"/> of <see cref="T:ILoggingProvider"/> to instantiate.</param>
 /// <returns><see cref="T:ILoggingProvider"/></returns>
 public static ILoggingProvider Create( Type t )
 {
     if ( t.NotNull() ) return ( t.GetInstance() as ILoggingProvider );
     else throw new PersistenceException(
                         String.Format( System.Globalization.CultureInfo.InvariantCulture,
                                         Resources.Strings.Logger_Invalid_Type,
                                         t.ToString() ) );
 }
Example #4
0
        /// <summary>
        /// Parameterized constructor.
        /// </summary>
        public RegisterAttribute(string contractName, Type contractType)
        {
            contractName.NotNullOrWhiteSpace("contractName");
            contractType.NotNull("contractType");

            this.ContractName = contractName;
            this.ContractType = contractType;
        }
        /// <summary>
        /// Get the properties for a given type
        /// </summary>
        /// <param name="instanceType"></param>
        /// <returns></returns>
        public static PropertyInfo[] GetPropertiesFromType(Type instanceType)
        {
            instanceType = instanceType.NotNull();

            PropertyInfo[] type;

            _propertyCache.TryGetValue(instanceType, out type);

            return type;
        }
Example #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="exceptionMessage">Exception message to be included in the new exception</param>
        /// <param name="exceptionType">Type of the new exception to be created</param>
        public AbstractHandler(
            string exceptionMessage,
            Type exceptionType)
        {
            exceptionMessage.NotNullOrEmpty(nameof(exceptionMessage));
            exceptionType.NotNull(nameof(exceptionType));
            exceptionType.Is<Exception>();

            _exceptionMessage = exceptionMessage;
            ExceptionType = exceptionType;
        }
        /// <summary>
        /// Generates the key that should be use to cache/retrieve the content
        /// for the given controllerType and action name
        /// </summary>
        /// <param name="controllerType">The controller type (must be ApiController)</param>
        /// <param name="actionName">The action name</param>
        /// <param name="context">The action context</param>
        /// <returns>The key for the given controller type and action name</returns>
        /// <exception cref="ArgumentException">If controller type is not an ApiController</exception>
        public virtual string Generate(
            Type controllerType,
            string actionName,
            HttpActionContext context)
        {
            controllerType.NotNull(nameof(controllerType));
            controllerType.Is<ApiController>();
            actionName.NotNullOrEmpty(nameof(actionName));
            context.NotNull(nameof(context));

            return "{0}-{1}".AsFormat(controllerType.FullName, actionName);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="exceptionType">Type of exception this policy refers to</param>
        /// <param name="action">What to do after the exception is handled</param>
        /// <param name="handlers">Handlers to execute on the exception</param>
        public ExceptionPolicyEntry(
            Type exceptionType,
            PostHandlingAction action,
            IEnumerable<IExceptionHandler> handlers)
        {
            exceptionType.NotNull(nameof(exceptionType));
            handlers.NotNullOrEmpty(nameof(handlers));

            ExceptionType = exceptionType;
            Action = action;
            _handlers = handlers.ToArray();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="controllerType">The controller type (must be ApiController)</param>
        /// <param name="actionName">The action name</param>
        /// <param name="cacheKeyGeneratorType">The type of the class responsible for generating the keys</param>
        public InvalidateXReferencedOutputCacheAttribute(
            Type controllerType,
            string actionName,
            Type cacheKeyGeneratorType = null)
        {
            controllerType.NotNull(nameof(controllerType));
            controllerType.Is<ApiController>();
            actionName.NotNullOrEmpty(nameof(actionName));

            ActionName = actionName;
            ControllerType = controllerType;
            CacheKeyGeneratorType = cacheKeyGeneratorType ?? typeof(DefaultCacheKeyGenerator);
        }
Example #10
0
        void IObjectContainer.RegisterInstance(Type type, object instance, string name)
        {
            type.NotNull("type");
            instance.NotNull("instance");

            var typeRegistration = new TypeRegistration(type, name);

            if(_registeredTypes.Contains(typeRegistration) || this.IsRegistered(type, name)) {
                throw new ApplicationException(string.Format("the type of '{0}' as name '{1}' has been registered.", type.FullName, name));
            }

            _registeredTypes.Add(typeRegistration);
            this.RegisterInstance(type, name, instance);
        }
Example #11
0
        void IObjectContainer.RegisterType(Type type, string name, Lifecycle lifetime)
        {
            type.NotNull("type");

            if(!type.IsClass || type.IsAbstract) {
                throw new ApplicationException(string.Format("the type of '{0}' must be a class and cannot be abstract.", type.FullName));
            }

            var typeRegistration = new TypeRegistration(type, name);

            if(_registeredTypes.Contains(typeRegistration) || this.IsRegistered(type, name)) {
                throw new ApplicationException(string.Format("the type of '{0}' as name '{1}' has been registered.", type.FullName, name));
            }

            _registeredTypes.Add(typeRegistration);
            this.RegisterType(type, name, lifetime);
        }
Example #12
0
        void IObjectContainer.RegisterType(Type from, Type to, string name, Lifecycle lifetime)
        {
            from.NotNull("from");
            to.NotNull("to");
            if(!to.IsClass || to.IsAbstract) {
                throw new ApplicationException(string.Format("the type of '{0}' must be a class and cannot be abstract.", to.FullName));
            }

            if(!from.IsAssignableFrom(to)) {
                throw new ApplicationException(string.Format("'{0}' does not extend '{1}'.", to.FullName, from.FullName));
            }

            var typeRegistration = new TypeRegistration(from, name);

            if(_registeredTypes.Contains(typeRegistration) || this.IsRegistered(from, name)) {
                throw new ApplicationException(string.Format("the type of '{0}' as name '{1}' has been registered.", to.FullName, name));
            }

            _registeredTypes.Add(typeRegistration);
            this.RegisterType(from, to, name, lifetime);
        }
Example #13
0
        bool IObjectContainer.IsRegistered(Type type, string name)
        {
            type.NotNull("type");

            return _registeredTypes.Contains(new TypeRegistration(type, name)) || this.IsRegistered(type, name);
        }
Example #14
0
 /// <summary>
 /// Parameterized constructor.
 /// </summary>
 public RegisterAttribute(Type contractType)
 {
     contractType.NotNull("contractType");
     this.ContractType = contractType;
 }