示例#1
0
        public void ConfigureContainer(ContainerBuilder builder)
        {
            var awsOptions = _configuration.GetAWSOptions(Ceph);

            builder.Register(x => x.Resolve <IOptions <CephOptions> >().Value).SingleInstance();
            builder.Register(x => x.Resolve <IOptions <ThrottlingOptions> >().Value).SingleInstance();
            builder.RegisterInstance(new CdnOptions {
                CdnUrl = new Uri("ams://unused")
            }).SingleInstance();
            builder.RegisterInstance(new DistributedLockOptions()).SingleInstance();
            builder.RegisterInstance(awsOptions).SingleInstance();

            builder.RegisterType <InMemoryLockFactory>().As <IDistributedLockFactory>().PreserveExistingDefaults().SingleInstance();
            builder.Register(
                x =>
            {
                var config            = awsOptions.DefaultClientConfig.ToS3Config();
                config.ForcePathStyle = true;

                var cephOptions = x.Resolve <CephOptions>();
                return(new Amazon.S3.AmazonS3Client(new BasicAWSCredentials(cephOptions.AccessKey, cephOptions.SecretKey), config));
            })
            .Named <IAmazonS3>(Ceph)
            .SingleInstance();
            builder.Register(
                x =>
            {
                var options = _configuration.GetAWSOptions(Aws);
                return(options.CreateServiceClient <IAmazonS3>());
            })
            .Named <IAmazonS3>(Aws)
            .SingleInstance();
            builder.RegisterType <S3MultipartUploadClient>()
            .As <IS3MultipartUploadClient>()
            .WithParameter(
                (parameterInfo, context) => parameterInfo.ParameterType == typeof(IAmazonS3),
                (parameterInfo, context) => context.ResolveNamed <IAmazonS3>(Ceph))
            .SingleInstance();
            builder.Register(
                x =>
            {
                var amazonS3        = x.ResolveNamed <IAmazonS3>(Ceph);
                var metricsProvider = x.Resolve <MetricsProvider>();
                return(new S3ClientPrometheusDecorator(new S3Client(amazonS3), metricsProvider, Labels.Backends.Ceph));
            })
            .Named <IS3Client>(Ceph)
            .PreserveExistingDefaults()
            .SingleInstance();
            builder.Register(
                x =>
            {
                var amazonS3        = x.ResolveNamed <IAmazonS3>(Aws);
                var metricsProvider = x.Resolve <MetricsProvider>();
                return(new S3ClientPrometheusDecorator(new S3Client(amazonS3), metricsProvider, Labels.Backends.Aws));
            })
            .Named <IS3Client>(Aws)
            .PreserveExistingDefaults()
            .SingleInstance();
            builder.RegisterType <CephS3Client>()
            .As <ICephS3Client>()
            .WithParameter(
                (parameterInfo, context) => parameterInfo.ParameterType == typeof(IS3Client),
                (parameterInfo, context) => context.ResolveNamed <IS3Client>(Ceph))
            .SingleInstance();
            builder.RegisterType <S3.AmazonS3Client>()
            .As <IAmazonS3Client>()
            .WithParameter(
                (parameterInfo, context) => parameterInfo.ParameterType == typeof(IS3Client),
                (parameterInfo, context) => context.ResolveNamed <IS3Client>(Aws))
            .SingleInstance();
            builder.RegisterType <DistributedLockManager>().SingleInstance();
            builder.RegisterType <TemplatesStorageReader>()
            .WithParameter(
                (parameterInfo, context) => parameterInfo.ParameterType == typeof(IS3Client),
                (parameterInfo, context) => context.Resolve <ICephS3Client>())
            .As <ITemplatesStorageReader>()
            .SingleInstance();
            builder.RegisterType <ObjectsStorageReader>()
            .WithParameter(
                (parameterInfo, context) => parameterInfo.ParameterType == typeof(IS3Client),
                (parameterInfo, context) => context.Resolve <ICephS3Client>())
            .As <IObjectsStorageReader>()
            .SingleInstance();
            builder.RegisterType <ImagePreviewService>()
            .WithParameter(
                (parameterInfo, context) => parameterInfo.ParameterType == typeof(IS3Client),
                (parameterInfo, context) => context.Resolve <ICephS3Client>())
            .SingleInstance();
            builder.RegisterType <RawFileStorageInfoProvider>().SingleInstance();
            builder.RegisterType <MetricsProvider>().SingleInstance();

            builder.RegisterType <MemoryBasedRequestLimiter>().As <IRequestLimiter>().SingleInstance();
            SixLabors.ImageSharp.Configuration.Default.MemoryAllocator =
                _environment.IsProduction()
                    ? ArrayPoolMemoryAllocatorFactory.CreateWithLimitedLargePooling()
                    : ArrayPoolMemoryAllocatorFactory.CreateWithLimitedSmallPooling();
        }
 public MemoryConsumptionTests(ITestOutputHelper output)
 {
     _output = output;
     Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocatorFactory.CreateWithLimitedSmallPooling();
 }