/// <summary>
        /// Creates a new instance of ApiControllerInfoBuilder.
        /// </summary>
        /// <param name="serviceName">Name of the controller</param>
        public ApiControllerBuilder(string serviceName)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ArgumentException("serviceName null or empty!", "serviceName");
            }

            if (!DynamicApiServiceNameHelper.IsValidServiceName(serviceName))
            {
                throw new ArgumentException("serviceName is not properly formatted! It must contain a single-depth namespace at least! For example: 'myapplication/myservice'.", "serviceName");
            }

            ServiceName          = serviceName;
            ServiceInterfaceType = typeof(T);

            _actionBuilders = new Dictionary <string, ApiControllerActionBuilder <T> >();

            foreach (var methodInfo in DynamicApiControllerActionHelper.GetMethodsOfType(typeof(T)))
            {
                var actionBuilder = new ApiControllerActionBuilder <T>(this, methodInfo);

                if (methodInfo.IsDefined(typeof(DisableDynamicWebApiAttribute), true))
                {
                    actionBuilder.DontCreateAction();
                }

                _actionBuilders[methodInfo.Name] = actionBuilder;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new instance of ApiControllerInfoBuilder.
        /// </summary>
        /// <param name="serviceName">Name of the controller</param>
        /// <param name="iocResolver">Ioc resolver</param>
        public ApiControllerBuilder(string serviceName, IIocResolver iocResolver)
        {
            Check.NotNull(iocResolver, nameof(iocResolver));

            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ArgumentException("serviceName null or empty!", "serviceName");
            }

            if (!DynamicApiServiceNameHelper.IsValidServiceName(serviceName))
            {
                throw new ArgumentException("serviceName is not properly formatted! It must contain a single-depth namespace at least! For example: 'myapplication/myservice'.", "serviceName");
            }

            _iocResolver = iocResolver;

            ServiceName          = serviceName;
            ServiceInterfaceType = typeof(T);

            _actionBuilders = new Dictionary <string, ApiControllerActionBuilder <T> >();

            foreach (var methodInfo in DynamicApiControllerActionHelper.GetMethodsOfType(typeof(T)))
            {
                var actionBuilder = new ApiControllerActionBuilder <T>(this, methodInfo);

                var remoteServiceAttr = methodInfo.GetSingleAttributeOrNull <RemoteServiceAttribute>();
                if (remoteServiceAttr != null && !remoteServiceAttr.IsEnabledFor(methodInfo))
                {
                    actionBuilder.DontCreateAction();
                }

                _actionBuilders[methodInfo.Name] = actionBuilder;
            }
        }