Пример #1
0
        /// <summary>
        /// Create a new factory using the specified configuration
        /// </summary>
        public LusidApiFactory(ApiConfiguration apiConfiguration)
        {
            if (apiConfiguration == null)
            {
                throw new ArgumentNullException(nameof(apiConfiguration));
            }

            // Validate Uris
            if (!Uri.TryCreate(apiConfiguration.TokenUrl, UriKind.Absolute, out var _))
            {
                throw new UriFormatException($"Invalid Token Uri: {apiConfiguration.TokenUrl}");
            }

            if (!Uri.TryCreate(apiConfiguration.ApiUrl, UriKind.Absolute, out var _))
            {
                throw new UriFormatException($"Invalid LUSID Uri: {apiConfiguration.ApiUrl}");
            }

            // Create configuration
            var tokenProvider = new ClientCredentialsFlowTokenProvider(apiConfiguration);
            var configuration = new TokenProviderConfiguration(tokenProvider)
            {
                BasePath = apiConfiguration.ApiUrl,
            };

            configuration.AddDefaultHeader("X-LUSID-Application", apiConfiguration.ApplicationName);

            _apis = Init(configuration);
        }
Пример #2
0
        /// <summary>
        /// Create an ILusidApiFactory using the specified Url and Token Provider
        /// </summary>
        public static ILusidApiFactory Build(string url, ITokenProvider tokenProvider)
        {
            lock (Lock)
            {
                var threadId = Thread.CurrentThread.ManagedThreadId;

                if (!ThreadFactories.TryGetValue(threadId, out var factory))
                {
                    // TokenProviderConfiguration.ApiClient is the client used by LusidApiFactory and is
                    // not threadsafe, so there needs to be a separate instance for each instance of LusidApiFactory
                    var config = new TokenProviderConfiguration(tokenProvider)
                    {
                        BasePath = url
                    };

                    factory = new LusidApiFactory(config);
                    ThreadFactories[threadId] = factory;
                }

                return(factory);
            }
        }