コード例 #1
0
        public void Build()
        {
            var types =
                from
                type in assembly.GetTypes()
                where
                (type.IsPublic || type.IsNestedPublic) &&
                type.IsInterface &&
                typeof(T).IsAssignableFrom(type) &&
                iocResolver.IsRegistered(type) &&
                !RemoteServiceAttribute.IsExplicitlyDisabledFor(type)
                select
                type;

            if (typePredicate != null)
            {
                types = types.Where(t => typePredicate(t));
            }

            foreach (var type in types)
            {
                var serviceName = serviceNameSelector != null
                    ? serviceNameSelector(type)
                    : GetConventionalServiceName(type);

                if (!string.IsNullOrWhiteSpace(servicePrefix))
                {
                    serviceName = servicePrefix + "/" + serviceName;
                }

                var builder = typeof(IDynamicApiControllerBuilder)
                              .GetMethod("For", BindingFlags.Public | BindingFlags.Instance)
                              .MakeGenericMethod(type)
                              .Invoke(dynamicApiControllerBuilder, new object[] { serviceName });

                if (filters != null)
                {
                    builder.GetType()
                    .GetMethod("WithFilters", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { filters });
                }

                if (isApiExplorerEnabled != null)
                {
                    builder.GetType()
                    .GetMethod("WithApiExplorer", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { isApiExplorerEnabled });
                }

                if (isProxyScriptingEnabled != null)
                {
                    builder.GetType()
                    .GetMethod("WithProxyScripts", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { isProxyScriptingEnabled.Value });
                }

                if (conventionalVerbs)
                {
                    builder.GetType()
                    .GetMethod("WithConventionalVerbs", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[0]);
                }

                if (forMethodsAction != null)
                {
                    builder.GetType()
                    .GetMethod("ForMethods", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { forMethodsAction });
                }

                builder.GetType()
                .GetMethod("Build", BindingFlags.Public | BindingFlags.Instance)
                .Invoke(builder, new object[0]);
            }
        }
コード例 #2
0
        public void Build()
        {
            var types =
                from
                type in _assembly.GetTypes()
                where
                (type.IsPublic || type.IsNestedPublic) &&
                type.IsInterface &&
                typeof(T).IsAssignableFrom(type) &&
                IocManager.Instance.IsRegistered(type) &&
                !RemoteServiceAttribute.IsExplicitlyDisabledFor(type)
                select
                type;

            if (_typePredicate != null)
            {
                types = types.Where(t => _typePredicate(t));
            }

            foreach (var type in types)
            {
                var serviceName = _serviceNameSelector != null
                    ? _serviceNameSelector(type)
                    : GetConventionalServiceName(type);

                if (!string.IsNullOrWhiteSpace(_servicePrefix))
                {
                    serviceName = _servicePrefix + "/" + serviceName;
                }

                var builder = typeof(DynamicApiControllerBuilder)
                              .GetMethod("For", BindingFlags.Public | BindingFlags.Static)
                              .MakeGenericMethod(type)
                              .Invoke(null, new object[] { serviceName });

                if (_filters != null)
                {
                    builder.GetType()
                    .GetMethod("WithFilters", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { _filters });
                }

                if (_conventionalVerbs)
                {
                    builder.GetType()
                    .GetMethod("WithConventionalVerbs", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[0]);
                }

                if (_forMethodsAction != null)
                {
                    builder.GetType()
                    .GetMethod("ForMethods", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { _forMethodsAction });
                }

                builder.GetType()
                .GetMethod("Build", BindingFlags.Public | BindingFlags.Instance)
                .Invoke(builder, new object[0]);
            }
        }