Esempio n. 1
0
        private void InitApiClient(TestContext context)
        {
            NUnit.Framework.TestContext.Out.WriteLine("Initialising API Client");
            var bookingsHttpClient = new HttpClient();

            bookingsHttpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("bearer", context.Tokens.BookingsApiBearerToken);
            BookingApiClient = BookingsApiClient.GetClient(context.Config.Services.BookingsApiUrl, bookingsHttpClient);

            var videoHttpClient = new HttpClient();

            videoHttpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("bearer", context.Tokens.VideoApiBearerToken);
            VideoApiClient = VideoApiClient.GetClient(context.Config.Services.VideoApiUrl, videoHttpClient);
        }
Esempio n. 2
0
 private static IBookingsApiClient BuildBookingsApiClient(HttpClient httpClient, ServiceSettings serviceSettings)
 {
     return(BookingsApiClient.GetClient(serviceSettings.BookingsApiUrl, httpClient));
 }
Esempio n. 3
0
        public void RegisterServices(IServiceCollection services, IConfiguration configuration)
        {
            var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions()));

            services.AddSingleton <IMemoryCache>(memoryCache);
            services.Configure <AzureAdConfiguration>(options =>
            {
                configuration.GetSection("AzureAd").Bind(options);
            });
            services.Configure <ServicesConfiguration>(options =>
            {
                configuration.GetSection("VhServices").Bind(options);
            });

            var serviceConfiguration = new ServicesConfiguration();

            configuration.GetSection("VhServices").Bind(serviceConfiguration);

            services.AddScoped <IAzureTokenProvider, AzureTokenProvider>();

            services.AddLogging(builder =>
                                builder.AddApplicationInsights(configuration["ApplicationInsights:InstrumentationKey"])
                                );

            services.AddScoped <ICloseConferenceService, CloseConferenceService>();
            services.AddScoped <IClearConferenceChatHistoryService, ClearConferenceChatHistoryService>();
            services.AddScoped <IAnonymiseHearingsConferencesDataService, AnonymiseHearingsConferencesDataService>();
            services.AddScoped <IRemoveHeartbeatsForConferencesService, RemoveHeartbeatsForConferencesService>();

            bool.TryParse(configuration["UseELinksStub"], out var useELinksStub);

            if (useELinksStub)
            {
                services.AddScoped <IELinksService, ELinksServiceStub>();
            }
            else
            {
                services.AddScoped <IELinksService, ELinksService>();
                services.AddTransient <ELinksApiDelegatingHandler>();
                services.AddHttpClient <IPeoplesClient, PeoplesClient>()
                .AddHttpMessageHandler <ELinksApiDelegatingHandler>()
                .AddTypedClient(httpClient =>
                {
                    var peoplesClient = new PeoplesClient(httpClient)
                    {
                        BaseUrl = serviceConfiguration.ELinksPeoplesBaseUrl
                    };
                    return((IPeoplesClient)peoplesClient);
                });
                services.AddHttpClient <ILeaversClient, LeaversClient>()
                .AddHttpMessageHandler <ELinksApiDelegatingHandler>()
                .AddTypedClient(httpClient =>
                {
                    var leaversClient = new LeaversClient(httpClient)
                    {
                        BaseUrl = serviceConfiguration.ELinksLeaversBaseUrl
                    };
                    return((ILeaversClient)leaversClient);
                });
            }

            services.AddTransient <VideoServiceTokenHandler>();
            services.AddTransient <BookingsServiceTokenHandler>();
            services.AddTransient <UserServiceTokenHandler>();

            services.AddHttpClient <IVideoApiClient, VideoApiClient>()
            .AddHttpMessageHandler <VideoServiceTokenHandler>()
            .AddTypedClient(httpClient =>
            {
                var client     = VideoApiClient.GetClient(httpClient);
                client.BaseUrl = serviceConfiguration.VideoApiUrl;
                client.ReadResponseAsString = true;
                return((IVideoApiClient)client);
            });

            services.AddHttpClient <IBookingsApiClient, BookingsApiClient>()
            .AddHttpMessageHandler <BookingsServiceTokenHandler>()
            .AddTypedClient(httpClient =>
            {
                var client     = BookingsApiClient.GetClient(httpClient);
                client.BaseUrl = serviceConfiguration.BookingsApiUrl;
                client.ReadResponseAsString = true;
                return((IBookingsApiClient)client);
            });

            services.AddHttpClient <IUserApiClient, UserApiClient>()
            .AddHttpMessageHandler <UserServiceTokenHandler>()
            .AddTypedClient(httpClient =>
            {
                var client     = UserApiClient.GetClient(httpClient);
                client.BaseUrl = serviceConfiguration.UserApiUrl;
                client.ReadResponseAsString = true;
                return((IUserApiClient)client);
            });
        }
 private static IBookingsApiClient BuildBookingsApiClient(HttpClient httpClient,
                                                          HearingServicesConfiguration servicesConfiguration)
 {
     return(BookingsApiClient.GetClient(servicesConfiguration.BookingsApiUrl, httpClient));
 }
        public static IServiceCollection AddCustomTypes(this IServiceCollection serviceCollection)
        {
            serviceCollection.AddHttpContextAccessor();
            serviceCollection.AddMemoryCache();
            serviceCollection.AddTransient <HearingApiTokenHandler>();
            serviceCollection.AddTransient <UserApiTokenHandler>();
            serviceCollection.AddTransient <VideoApiTokenHandler>();
            serviceCollection.AddTransient <NotificationApiTokenHandler>();
            serviceCollection.AddTransient <IHearingsService, HearingsService>();
            serviceCollection.AddScoped <ITokenProvider, TokenProvider>();
            serviceCollection.AddScoped <IUserAccountService, UserAccountService>();
            serviceCollection.AddScoped <AzureAdConfiguration>();
            serviceCollection.AddSingleton <IClaimsCacheProvider, MemoryClaimsCacheProvider>();
            serviceCollection.AddScoped <ICachedUserClaimBuilder, CachedUserClaimBuilder>();
            serviceCollection.AddSingleton <IPollyRetryService, PollyRetryService>();

            // Build the hearings api client using a reusable HttpClient factory and predefined base url
            var container = serviceCollection.BuildServiceProvider();
            var settings  = container.GetService <IOptions <ServiceConfiguration> >().Value;

            serviceCollection.AddHttpClient <IBookingsApiClient, BookingsApiClient>()
            .AddHttpMessageHandler(() => container.GetService <HearingApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = BookingsApiClient.GetClient(httpClient);
                client.BaseUrl = settings.BookingsApiUrl;
                client.ReadResponseAsString = true;
                return((IBookingsApiClient)client);
            });

            serviceCollection.AddHttpClient <IUserApiClient, UserApiClient>()
            .AddHttpMessageHandler(() => container.GetService <UserApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = UserApiClient.GetClient(httpClient);
                client.BaseUrl = settings.UserApiUrl;
                client.ReadResponseAsString = true;
                return((IUserApiClient)client);
            });

            serviceCollection.AddHttpClient <IVideoApiClient, VideoApiClient>()
            .AddHttpMessageHandler(() => container.GetService <VideoApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = VideoApiClient.GetClient(httpClient);
                client.BaseUrl = settings.VideoApiUrl;
                client.ReadResponseAsString = true;
                return((IVideoApiClient)client);
            });

            serviceCollection.AddHttpClient <INotificationApiClient, NotificationApiClient>()
            .AddHttpMessageHandler(() => container.GetService <NotificationApiTokenHandler>())
            .AddTypedClient(httpClient =>
            {
                var client     = NotificationApiClient.GetClient(httpClient);
                client.BaseUrl = settings.NotificationApiUrl;
                client.ReadResponseAsString = true;
                return((INotificationApiClient)client);
            });

            serviceCollection.AddHttpClient <IPublicHolidayRetriever, UkPublicHolidayRetriever>();
            serviceCollection.AddTransient <IUserIdentity, UserIdentity>((ctx) =>
            {
                var userPrincipal = ctx.GetService <IHttpContextAccessor>().HttpContext.User;

                return(new UserIdentity(userPrincipal));
            });

            serviceCollection.AddSingleton <IValidator <EditHearingRequest>, EditHearingRequestValidator>();

            return(serviceCollection);
        }