Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ophthalmology.DataAccess.Services
- {
- public abstract class GenericService<T> where T : new()
- {
- static string _baseUrl = null;
- public GenericService(string serviceDiscoveryUrl)
- {
- ServiceDiscoveryClient.ServiceDiscoveryClient.ServiceDiscoveryUrl = serviceDiscoveryUrl;
- }
- public async Task Initialize(AuthenticationHeaderValue authorization)
- {
- if (string.IsNullOrEmpty(GetKey()) || string.IsNullOrEmpty(_baseUrl))
- _baseUrl = await ServiceDiscoveryClient.ServiceDiscoveryClient.GetEndpoint(GetKey(), authorization);
- }
- public async Task Initialize(string applicationID, string applicationVersion, string tenantId, string facilityId)
- {
- if (string.IsNullOrEmpty(GetKey()) || string.IsNullOrEmpty(_baseUrl))
- _baseUrl = await ServiceDiscoveryClient.ServiceDiscoveryClient.GetEndpoint(GetKey(), applicationID, applicationVersion, tenantId, facilityId);
- }
- public string GetBaseUrl()
- {
- return _baseUrl;
- }
- public abstract string GetKey();
- public abstract T GetClientClass(string baseUrl, HttpClient httpClient);
- public async Task<T> GetClient(AuthenticationHeaderValue authorization)
- {
- System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();
- if (authorization != null)
- {
- httpClient.DefaultRequestHeaders.Authorization = authorization;
- }
- await Initialize(authorization);
- return GetClientClass(GetBaseUrl(), httpClient);
- }
- public async Task<T> GetClient(string applicationID, string applicationVersion, string tenantId, string facilityId)
- {
- System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();
- await Initialize(applicationID, applicationVersion, tenantId, facilityId);
- return GetClientClass(GetBaseUrl(), httpClient);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement