Ejemplo n.º 1
0
        static Program()
        {
            var pathMapper = new PathMapper(AppDomain.CurrentDomain.SetupInformation.ApplicationBase);

            string configPath = pathMapper.MapPath(ConfigFilePath);

            CabinetFactory       = new FileCabinetFactory();
            CabinetConfigFactory = new FileCabinetConfigConverterFactory();
            CabinetConfigStore   = new FileCabinetProviderConfigStore(configPath, CabinetConfigFactory);

            CabinetFactory
            .RegisterFileSystemProvider()
            .RegisterS3Provider();

            CabinetConfigFactory
            .RegisterFileSystemConfigConverter(pathMapper)
            .RegisterAmazonS3ConfigConverter();
        }
 public FileCabinetConverterFactoryFacts()
 {
     this.converterFactory = new FileCabinetConfigConverterFactory();
 }
Ejemplo n.º 3
0
        public ContainerBuilder ConfigureAutoFac()
        {
            var builder = new ContainerBuilder();

            // Web Registrations
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType <System.IO.Abstractions.FileSystem>().As <System.IO.Abstractions.IFileSystem>();

            // Cabinet.Web Registrations

            builder.RegisterType <FileTypeProvider>().As <IFileTypeProvider>();
            builder.RegisterType <UploadValidator>().As <IUploadValidator>();
            builder.RegisterType <UploadKeyProvider>().As <IKeyProvider>();
            builder.RegisterInstance <IValidationSettings>(new ValidationSettings {
                AllowedFileCategories = new FileTypeCategory[] { FileTypeCategory.Document, FileTypeCategory.Image },
                MaxSize = (long)ByteSize.FromMegaBytes(30).Bytes,
                MinSize = 1
            });

            // Cabinet Registrations
            var pathMapper = new PathMapper(AppDomain.CurrentDomain.SetupInformation.ApplicationBase);

            string configPath = pathMapper.MapPath(ConfigFilePath);

            var cabinetFactory       = new FileCabinetFactory();
            var cabinetConfigFactory = new FileCabinetConfigConverterFactory();
            var cabinetConfigStore   = new FileCabinetProviderConfigStore(configPath, cabinetConfigFactory);

            cabinetFactory
            .RegisterFileSystemProvider()
            .RegisterS3Provider()
            .RegisterMigratorProvider();

            cabinetConfigFactory
            .RegisterFileSystemConfigConverter(pathMapper)
            .RegisterAmazonS3ConfigConverter()
            .RegisterMigratorConfigConverter(cabinetConfigStore);

            builder.RegisterInstance <IPathMapper>(pathMapper);
            builder.RegisterInstance <IFileCabinetFactory>(cabinetFactory);
            builder.RegisterInstance <IFileCabinetConfigConverterFactory>(cabinetConfigFactory);
            builder.RegisterInstance <ICabinetProviderConfigStore>(cabinetConfigStore);

            // Register one cabinet for the whole app
            builder.Register <IFileCabinet>((c) => {
                var configStore = c.Resolve <ICabinetProviderConfigStore>();
                var config      = configStore.GetConfig("ondisk");
                return(cabinetFactory.GetCabinet(config));
            });

            // Manual registration examples
            //builder.Register((c) => {
            //    var mapper = c.Resolve<IPathMapper>();
            //    string uploadDir = mapper.MapPath("~/App_Data/Uploads");
            //    var fileConfig = new FileSystemCabinetConfig(uploadDir, true);
            //    return cabinetFactory.GetCabinet(fileConfig);
            //});

            //builder.Register((c) => {
            //    var s3Config = new AmazonS3CabinetConfig("test-bucket", RegionEndpoint.APSoutheast2, new StoredProfileAWSCredentials());
            //    return cabinetFactory.GetCabinet(s3Config);
            //});

            return(builder);
        }