using FileRepository.Repositories; using Microsoft.Extensions.Configuration; using System; namespace FileRepository { /// /// A factory to enable consumers of this package to easily get a specific type of repository. /// public static class Factory { /// /// An enum to restrict users to only select valid repository types. /// public enum RepositoryType { /// /// An enum member for storing files on disk. /// Disk, /// /// An enum member for storing files in a MongoDb NoSQL database. /// MongoDb, /// /// An enum member for storing files on AWS S3. /// S3, /// /// An enum member for storing files on a remote drive using SFTP. /// Sftp, /// /// An enum member for storing files in an SQL database. /// Sql, } /// /// Initialise an implementation of IFileRepository based on a selected enum member. /// /// The type of repository to initialise, based on the enum member. /// The configuration to initialise the repository. /// Returns an initialised repository. public static IFileRepository GetFileRepository(RepositoryType repositoryType, IConfiguration config) { switch (repositoryType) { case RepositoryType.Disk: throw new NotImplementedException(); return new DiskRepository(config); case RepositoryType.MongoDb: throw new NotImplementedException(); return new MongoDbRepository(config); case RepositoryType.S3: throw new NotImplementedException(); return new S3Repository(config); case RepositoryType.Sftp: return new SftpRepository(config); case RepositoryType.Sql: throw new NotImplementedException(); return new SqlRepository(config); default: string repositoryName = Enum.GetName(typeof(RepositoryType), value: repositoryType); throw new ArgumentException($"{repositoryName} is not a valid repository type."); } } } }