Пример #1
0
        public static void Setup(WebAssemblyHostBuilder builder, ApiServiceSettings settings)
        {
            builder.Services.TryAddSingleton <ApiService>();
            builder.Services.TryAddSingleton <IObjectConverter, DefaultObjectConverter>();

            SetupHttpClient(builder, settings);
            SetupApiInterfacesInstances(builder, settings);
        }
Пример #2
0
        private static void SetupHttpClient(WebAssemblyHostBuilder builder, ApiServiceSettings settings)
        {
            var httpClient = settings?.HttpClient
                             ?? new HttpClient
            {
                BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
            };

            builder.Services.TryAddSingleton(httpClient);
        }
        public static bool CheckForConventions(Type apiInterface, ApiServiceSettings settings)
        {
            if (conventionCheckPassedTypes.Contains(apiInterface))
            {
                return(true);
            }

            var throwException = (settings?.OnApiInterfaceConventionViolated ?? OnApiInterfaceConventionViolated.SkipAndContinueRunning)
                                 == OnApiInterfaceConventionViolated.ThrowException;

            var success = CheckForInterfaceType(apiInterface, throwException) &&
                          CheckForMaxOneComplexParameter(apiInterface, throwException) &&
                          CheckForNameDifference(apiInterface, throwException);

            if (success)
            {
                conventionCheckPassedTypes.Add(apiInterface);
            }
            return(success);
        }
Пример #4
0
        private static void SetupApiInterfacesInstances(WebAssemblyHostBuilder builder, ApiServiceSettings settings)
        {
            if (settings?.ApiInterfacesSources == null)
            {
                return;
            }

            foreach (var apiInterface in settings.ApiInterfacesSources.SelectMany(ai => ai.ApiInterfaces).ToList())
            {
                if (!ApiConventionManager.CheckForConventions(apiInterface, settings))
                {
                    continue;
                }

                AddServiceForApiInterfaceType(apiInterface, builder);
            }
        }