public static BaGetApplication AddAwsS3Storage(this BaGetApplication app) { app.Services.AddBaGetOptions <S3StorageOptions>(nameof(BaGetOptions.Storage)); app.Services.AddTransient <S3StorageService>(); app.Services.TryAddTransient <IStorageService>(provider => provider.GetRequiredService <S3StorageService>()); app.Services.AddProvider <IStorageService>((provider, config) => { if (!config.HasStorageType("AwsS3")) { return(null); } return(provider.GetRequiredService <S3StorageService>()); }); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <S3StorageOptions> >().Value; var config = new AmazonS3Config { RegionEndpoint = options.Region != null ? RegionEndpoint.GetBySystemName(options.Region) : null, ServiceURL = options.ServiceUrl }; if (options.UseInstanceProfile) { var credentials = FallbackCredentialsFactory.GetCredentials(); return(new AmazonS3Client(credentials, config)); } if (!string.IsNullOrEmpty(options.AssumeRoleArn)) { var credentials = FallbackCredentialsFactory.GetCredentials(); var assumedCredentials = AssumeRoleAsync( credentials, options.AssumeRoleArn, $"BaGet-Session-{Guid.NewGuid()}") .GetAwaiter() .GetResult(); return(new AmazonS3Client(assumedCredentials, config)); } if (!string.IsNullOrEmpty(options.AccessKey)) { return(new AmazonS3Client( new BasicAWSCredentials( options.AccessKey, options.SecretKey), config)); } return(new AmazonS3Client(config)); }); return(app); }
public static BaGetApplication AddAliyunOssStorage(this BaGetApplication app) { app.Services.AddBaGetOptions <AliyunStorageOptions>(nameof(BaGetOptions.Storage)); app.Services.AddTransient <AliyunStorageService>(); app.Services.TryAddTransient <IStorageService>(provider => provider.GetRequiredService <AliyunStorageService>()); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AliyunStorageOptions> >().Value; return(new OssClient(options.Endpoint, options.AccessKey, options.AccessKeySecret)); }); app.Services.AddProvider <IStorageService>((provider, config) => { if (!config.HasStorageType("AliyunOss")) { return(null); } return(provider.GetRequiredService <AliyunStorageService>()); }); return(app); }
public static BaGetApplication AddFileStorage( this BaGetApplication app, Action <FileSystemStorageOptions> configure) { app.AddFileStorage(); app.Services.Configure(configure); return(app); }
public static BaGetApplication AddAzureTableDatabase( this BaGetApplication app, Action <AzureTableOptions> configure) { app.AddAzureTableDatabase(); app.Services.Configure(configure); return(app); }
public static BaGetApplication AddAzureSearch( this BaGetApplication app, Action <AzureSearchOptions> configure) { app.AddAzureSearch(); app.Services.Configure(configure); return(app); }
public static BaGetApplication AddAzureBlobStorage( this BaGetApplication app, Action <AzureBlobStorageOptions> configure) { app.AddAzureBlobStorage(); app.Services.Configure(configure); return(app); }
public static BaGetApplication AddPostgreSqlDatabase( this BaGetApplication app, Action <DatabaseOptions> configure) { app.AddPostgreSqlDatabase(); app.Services.Configure(configure); return(app); }
public static BaGetApplication AddGoogleCloudStorage( this BaGetApplication app, Action <GoogleCloudStorageOptions> configure) { app.AddGoogleCloudStorage(); app.Services.Configure(configure); return(app); }
public static BaGetApplication AddMySqlDatabase(this BaGetApplication app) { app.Services.AddBaGetDbContextProvider <MySqlContext>("MySql", (provider, options) => { var databaseOptions = provider.GetRequiredService <IOptionsSnapshot <DatabaseOptions> >(); options.UseMySql(databaseOptions.Value.ConnectionString); }); return(app); }
public static BaGetApplication AddAzureSearch(this BaGetApplication app) { app.Services.AddBaGetOptions <AzureSearchOptions>(nameof(BaGetOptions.Search)); app.Services.AddTransient <AzureSearchBatchIndexer>(); app.Services.AddTransient <AzureSearchService>(); app.Services.AddTransient <AzureSearchIndexer>(); app.Services.AddTransient <IndexActionBuilder>(); app.Services.TryAddTransient <ISearchService>(provider => provider.GetRequiredService <AzureSearchService>()); app.Services.TryAddTransient <ISearchIndexer>(provider => provider.GetRequiredService <AzureSearchIndexer>()); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureSearchOptions> >().Value; var credentials = new SearchCredentials(options.ApiKey); return(new SearchServiceClient(options.AccountName, credentials)); }); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureSearchOptions> >().Value; var credentials = new SearchCredentials(options.ApiKey); return(new SearchIndexClient(options.AccountName, PackageDocument.IndexName, credentials)); }); app.Services.AddProvider <ISearchService>((provider, config) => { if (!config.HasSearchType("AzureSearch")) { return(null); } return(provider.GetRequiredService <AzureSearchService>()); }); app.Services.AddProvider <ISearchIndexer>((provider, config) => { if (!config.HasSearchType("AzureSearch")) { return(null); } return(provider.GetRequiredService <AzureSearchIndexer>()); }); return(app); }
public static BaGetApplication AddAzureBlobStorage(this BaGetApplication app) { app.Services.AddBaGetOptions <AzureBlobStorageOptions>(nameof(BaGetOptions.Storage)); app.Services.AddTransient <BlobStorageService>(); app.Services.TryAddTransient <IStorageService>(provider => provider.GetRequiredService <BlobStorageService>()); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureBlobStorageOptions> >().Value; if (!string.IsNullOrEmpty(options.ConnectionString)) { return(CloudStorageAccount.Parse(options.ConnectionString)); } return(new CloudStorageAccount( new StorageCredentials( options.AccountName, options.AccessKey), useHttps: true)); }); app.Services.AddTransient(provider => { var options = provider.GetRequiredService <IOptionsSnapshot <AzureBlobStorageOptions> >().Value; var account = provider.GetRequiredService <CloudStorageAccount>(); var client = account.CreateCloudBlobClient(); return(client.GetContainerReference(options.Container)); }); app.Services.AddProvider <IStorageService>((provider, config) => { if (!config.HasStorageType("AzureBlobStorage")) { return(null); } return(provider.GetRequiredService <BlobStorageService>()); }); return(app); }
private void ConfigureBaGetApplication(BaGetApplication app) { // Add database providers. app.AddAzureTableDatabase(); app.AddMySqlDatabase(); app.AddPostgreSqlDatabase(); app.AddSqliteDatabase(); app.AddSqlServerDatabase(); // Add storage providers. app.AddFileStorage(); app.AddAliyunOssStorage(); app.AddAwsS3Storage(); app.AddAzureBlobStorage(); app.AddGoogleCloudStorage(); // Add search providers. app.AddAzureSearch(); }
public static BaGetApplication AddGoogleCloudStorage(this BaGetApplication app) { app.Services.AddBaGetOptions <GoogleCloudStorageOptions>(nameof(BaGetOptions.Storage)); app.Services.AddTransient <GoogleCloudStorageService>(); app.Services.TryAddTransient <IStorageService>(provider => provider.GetRequiredService <GoogleCloudStorageService>()); app.Services.AddProvider <IStorageService>((provider, config) => { if (!config.HasStorageType("GoogleCloud")) { return(null); } return(provider.GetRequiredService <GoogleCloudStorageService>()); }); return(app); }
public static BaGetApplication AddFileStorage(this BaGetApplication app) { app.Services.TryAddTransient <IStorageService>(provider => provider.GetRequiredService <FileStorageService>()); return(app); }
public static BaGetApplication AddNullSearch(this BaGetApplication app) { app.Services.TryAddTransient <ISearchIndexer>(provider => provider.GetRequiredService <NullSearchIndexer>()); app.Services.TryAddTransient <ISearchService>(provider => provider.GetRequiredService <NullSearchService>()); return(app); }
public static BaGetApplication AddAzureTableDatabase(this BaGetApplication app) { app.Services.AddBaGetOptions <AzureTableOptions>(nameof(BaGetOptions.Database)); app.Services.AddTransient <TablePackageDatabase>(); app.Services.AddTransient <TableOperationBuilder>(); app.Services.AddTransient <TableSearchService>(); app.Services.TryAddTransient <IPackageDatabase>(provider => provider.GetRequiredService <TablePackageDatabase>()); app.Services.TryAddTransient <ISearchService>(provider => provider.GetRequiredService <TableSearchService>()); app.Services.TryAddTransient <ISearchIndexer>(provider => provider.GetRequiredService <NullSearchIndexer>()); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureTableOptions> >().Value; return(TableStorageAccount.Parse(options.ConnectionString)); }); app.Services.AddTransient(provider => { var account = provider.GetRequiredService <TableStorageAccount>(); return(account.CreateCloudTableClient()); }); app.Services.AddProvider <IPackageDatabase>((provider, config) => { if (!config.HasDatabaseType("AzureTable")) { return(null); } return(provider.GetRequiredService <TablePackageDatabase>()); }); app.Services.AddProvider <ISearchService>((provider, config) => { if (!config.HasSearchType("Database")) { return(null); } if (!config.HasDatabaseType("AzureTable")) { return(null); } return(provider.GetRequiredService <TableSearchService>()); }); app.Services.AddProvider <ISearchIndexer>((provider, config) => { if (!config.HasSearchType("Database")) { return(null); } if (!config.HasDatabaseType("AzureTable")) { return(null); } return(provider.GetRequiredService <NullSearchIndexer>()); }); return(app); }