Exemple #1
0
        /// <summary>
        /// DIを実行する
        /// </summary>
        /// <param name="utcNow">TimeProviderに渡す日時</param>
        /// <param name="appSettings">アプリケーション設定を上書きする場合は指定する</param>
        /// <param name="isSeriviceError">サービスで例外を強制的に発生させる場合はtrueを指定する</param>
        private void DependencyInjection(DateTime utcNow, Dictionary <string, string> appSettings = null, bool isSeriviceError = false)
        {
            // Repository生成
            TestDiProviderBuilder builder = new TestDiProviderBuilder();

            builder.ServiceCollection.AddTransient <DevicesController>();
            if (isSeriviceError)
            {
                // Serviceの各メソッドで例外を発生させるクラスに置き換える
                builder.ServiceCollection.AddTransient <IDeviceService, TestDeviceService>();
            }
            builder.ServiceCollection.AddTransient <DeliveringBlob>();
            builder.ServiceCollection.AddSingleton <myUtility.ITimeProvider>(UnitTestHelper.CreateTimeProvider(utcNow));
            builder.AddConfigures(appSettings);

            _serviceLogs   = new List <TestLog>();
            _serviceLogger = new TestLogger <DeviceService>(_serviceLogs);
            builder.ServiceCollection.AddSingleton <ILogger <DeviceService> >(_serviceLogger);

            // DI後したクラスを作成する
            ServiceProvider provider = builder.Build();

            _controller     = provider.GetService <DevicesController>();
            _deliveringBlob = provider.GetService <DeliveringBlob>();
            _appSettings    = provider.GetService <myUtility.AppSettings>();
        }
Exemple #2
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="settings">AppSettings</param>
        /// <param name="deliveringBlob">DeliveringBlob</param>
        /// <param name="polly">BlobPolly</param>
        /// <param name="logger">Logger</param>
        public DeliveringBlobRepository(
            AppSettings settings,
            DeliveringBlob deliveringBlob,
            BlobPolly polly,
            ILogger <DeliveringBlobRepository> logger)
        {
            Assert.IfNull(settings);
            Assert.IfNull(deliveringBlob);
            Assert.IfNull(logger);
            Assert.IfNull(polly);

            _settings       = settings;
            _deliveringBlob = deliveringBlob;
            _log            = logger;
            _polly          = polly;
        }