public static IServiceCollection AddStorageManager(this IServiceCollection services, StorageOptions options, IHealthChecksBuilder healthChecksBuilder = null) { if (options.UsedAzure()) { services.AddAzureBlobStorageManager(options.Azure); if (healthChecksBuilder != null) { healthChecksBuilder.AddAzureBlobStorage( options.Azure.ConnectionString, containerName: options.Azure.Container, name: "Storage (Azure Blob)", failureStatus: HealthStatus.Degraded); } } else if (options.UsedAmazon()) { services.AddAmazonS3StorageManager(options.Amazon); if (healthChecksBuilder != null) { healthChecksBuilder.AddS3( s3 => { s3.AccessKey = options.Amazon.AccessKeyID; s3.SecretKey = options.Amazon.SecretAccessKey; s3.BucketName = options.Amazon.BucketName; s3.S3Config = new AmazonS3Config { RegionEndpoint = RegionEndpoint.GetBySystemName(options.Amazon.RegionEndpoint), }; }, name: "Storage (Amazon S3)", failureStatus: HealthStatus.Degraded); } } else if (options.UsedLocal()) { services.AddLocalStorageManager(options.Local); if (healthChecksBuilder != null) { healthChecksBuilder.AddFilePathWrite(options.Local.Path, name: "Storage (Local Directory)", failureStatus: HealthStatus.Degraded); } } else { services.AddFakeStorageManager(); } return(services); }
public static IServiceCollection AddStorageModule(this IServiceCollection services, StorageOptions storageOptions, MessageBrokerOptions messageBrokerOptions, string connectionString, string migrationsAssembly = "") { services.AddDbContext <StorageDbContext>(options => options.UseSqlServer(connectionString, sql => { if (!string.IsNullOrEmpty(migrationsAssembly)) { sql.MigrationsAssembly(migrationsAssembly); } })) .AddScoped <IRepository <FileEntry, Guid>, Repository <FileEntry, Guid> >(); DomainEvents.RegisterHandlers(Assembly.GetExecutingAssembly(), services); services.AddMessageHandlers(Assembly.GetExecutingAssembly()); if (storageOptions.UsedAzure()) { services.AddSingleton <IFileStorageManager>(new AzureBlobStorageManager(storageOptions.Azure.ConnectionString, storageOptions.Azure.Container)); } else if (storageOptions.UsedAmazon()) { services.AddSingleton <IFileStorageManager>( new AmazonS3StorageManager( storageOptions.Amazon.AccessKeyID, storageOptions.Amazon.SecretAccessKey, storageOptions.Amazon.BucketName, storageOptions.Amazon.RegionEndpoint)); } else if (storageOptions.UsedLocal()) { services.AddSingleton <IFileStorageManager>(new LocalFileStorageManager(storageOptions.Local.Path)); } else if (storageOptions.UsedFake()) { services.AddSingleton <IFileStorageManager>(new FakeStorageManager()); } services.AddMessageBusSender <FileUploadedEvent>(messageBrokerOptions); services.AddMessageBusSender <FileDeletedEvent>(messageBrokerOptions); return(services); }