Esempio n. 1
0
        public static void ConfigureContainer(IUnityContainer container)
        {
            container.RegisterFactory <HttpClient>(_ => HttpClientExtensions.CreateHttpClient(), new TransientLifetimeManager());

            container.RegisterFactory <StaticLicenseConfiguration>(ResolveStaticLicenseConfiguration, new TransientLifetimeManager());
            container.RegisterType <ISourceCodeParser, SourceCodeParser>(new TransientLifetimeManager());
            container.RegisterType <ILicenseCache, LicenseCache>(new ContainerControlledLifetimeManager());
            container.RegisterType <ILicenseResolver, LicenseResolver>(new TransientLifetimeManager());
            container.RegisterType <IPackageRepository, PackageRepository>(new TransientLifetimeManager());

            // nuget
            container.RegisterFactory <NuGetConfiguration>(ResolveNuGetConfiguration, new ContainerControlledLifetimeManager());
            container.RegisterType <ISourceCodeReferenceProvider, NuGetSourceCodeReferenceProvider>(PackageSources.NuGet, new TransientLifetimeManager());
            container.RegisterType <IPackageResolver, NuGetPackageResolver>(PackageSources.NuGet, new TransientLifetimeManager());
            container.RegisterType <ILicenseSourceByUrl, NuGetLicenseSource>(KnownHosts.NuGetLicense, new TransientLifetimeManager());
            container.RegisterType <IPackageRepositoryAdapter, NuGetPackageRepositoryAdapter>(PackageSources.NuGet, new TransientLifetimeManager());

            // npm
            container.RegisterFactory <NpmConfiguration>(ResolveNpmConfiguration, new ContainerControlledLifetimeManager());
            container.RegisterType <ISourceCodeReferenceProvider, NpmSourceCodeReferenceProvider>(PackageSources.Npm, new TransientLifetimeManager());
            container.RegisterType <IPackageRepositoryAdapter, NpmPackageRepositoryAdapter>(PackageSources.Npm, new TransientLifetimeManager());
            container.RegisterType <IPackageResolver, NpmPackageResolver>(PackageSources.Npm, new TransientLifetimeManager());

            // github
            container.RegisterFactory <GitHubConfiguration>(ResolveGitHubConfiguration, new ContainerControlledLifetimeManager());
            container.RegisterType <ILicenseSourceByUrl, GitHubLicenseSource>(KnownHosts.GitHub, new TransientLifetimeManager());
            container.RegisterType <ILicenseSourceByUrl, GitHubLicenseSource>(KnownHosts.GitHubRaw, new TransientLifetimeManager());
            container.RegisterType <ILicenseSourceByUrl, GitHubLicenseSource>(KnownHosts.GitHubApi, new TransientLifetimeManager());

            // custom
            container.RegisterType <IPackageRepositoryAdapter, CustomPackageRepositoryAdapter>(PackageSources.Custom, new TransientLifetimeManager());
        }
Esempio n. 2
0
        public HttpClient GetClientForEndpoint(string endpointName)
        {
            if (_endpointToHttpClient.TryGetValue(endpointName, out HttpClient storedHttpClient))
            {
                return(storedHttpClient);
            }
            if (!_endpointToBaseUrl.TryGetValue(endpointName, out string baseUrl))
            {
                throw new EndpointNotConfiguredException(endpointName);
            }

            var client = HttpClientExtensions.CreateHttpClient(baseUrl);

            _endpointToHttpClient.TryAdd(endpointName, client);

            return(client);
        }