コード例 #1
0
        public async Task TestInitialize()
        {
            var messagesTable = new AzureCloudTable(ConnectionString, "MessagesTable");
            await messagesTable.CreateIfNotExistsAsync();

            var messageStore = new AzureTableMessagesStore(messagesTable);

            var conversationsTable = new AzureCloudTable(ConnectionString, "ConversationsTable");
            await conversationsTable.CreateIfNotExistsAsync();

            store = new AzureTableConversationsStore(conversationsTable, messageStore);
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: NaderAlAwar/ChatService
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.AddApiVersioning(
                o =>
            {
                o.AssumeDefaultVersionWhenUnspecified = true;
                o.DefaultApiVersion = new ApiVersion(1, 0);
            });

            var azureStorageSettings        = GetSettings <AzureStorageSettings>();
            var notificationServiceSettings = GetSettings <NotificationServiceSettings>();
            var faultToleranceSettings      = GetSettings <FaultToleranceSettings>();

            services.AddSingleton <IMetricsClient>(context =>
            {
                var metricsClientFactory = new MetricsClientFactory(context.GetRequiredService <ILoggerFactory>(),
                                                                    TimeSpan.FromSeconds(15));
                return(metricsClientFactory.CreateMetricsClient <LoggerMetricsClient>());
            });

            TimeoutPolicy        timeoutPolicy        = Policy.Timeout(faultToleranceSettings.TimeoutLength, TimeoutStrategy.Pessimistic);
            CircuitBreakerPolicy circuitBreakerPolicy = Policy
                                                        .Handle <Exception>()
                                                        .CircuitBreaker(
                exceptionsAllowedBeforeBreaking: faultToleranceSettings.ExceptionsAllowedBeforeBreaking,
                durationOfBreak: TimeSpan.FromMinutes(faultToleranceSettings.DurationOfBreakInMinutes)
                );
            PolicyWrap policyWrap = Policy.Wrap(circuitBreakerPolicy, timeoutPolicy);

            services.AddSingleton <ISyncPolicy>(policyWrap);

            QueueClient queueClient = new QueueClient(notificationServiceSettings.ServiceBusConnectionString,
                                                      notificationServiceSettings.QueueName);
            ServiceBusNotificationServiceClient notificationService = new ServiceBusNotificationServiceClient(queueClient);

            services.AddSingleton <INotificationService>(context =>
                                                         new NotificationServiceMetricsDecorator(
                                                             new NotificationServiceFaultToleranceDecorator(
                                                                 notificationService,
                                                                 context.GetRequiredService <ISyncPolicy>()),
                                                             context.GetRequiredService <IMetricsClient>()));

            AzureCloudTable        profileCloudTable = new AzureCloudTable(azureStorageSettings.ConnectionString, azureStorageSettings.ProfilesTableName);
            AzureTableProfileStore profileStore      = new AzureTableProfileStore(profileCloudTable);

            services.AddSingleton <IProfileStore>(context =>
                                                  new ProfileStoreMetricsDecorator(
                                                      new ProfileStoreFaultToleranceDecorator(
                                                          profileStore,
                                                          context.GetRequiredService <ISyncPolicy>()),
                                                      context.GetRequiredService <IMetricsClient>()));

            AzureCloudTable         messagesCloudTable = new AzureCloudTable(azureStorageSettings.ConnectionString, azureStorageSettings.MessagesTableName);
            AzureTableMessagesStore messagesStore      = new AzureTableMessagesStore(messagesCloudTable);

            services.AddSingleton <IMessagesStore>(context =>
                                                   new MessagesStoreMetricsDecorator(
                                                       new MessagesStoreFaultToleranceDecorator(
                                                           messagesStore,
                                                           context.GetRequiredService <ISyncPolicy>()),
                                                       context.GetRequiredService <IMetricsClient>()));

            AzureCloudTable conversationsCloudTable         = new AzureCloudTable(azureStorageSettings.ConnectionString, azureStorageSettings.UsersTableName);
            AzureTableConversationsStore conversationsStore = new AzureTableConversationsStore(conversationsCloudTable, messagesStore);

            services.AddSingleton <IConversationsStore>(context =>
                                                        new ConversationStoreMetricsDecorator(
                                                            new ConversationsStoreFaultToleranceDecorator(
                                                                conversationsStore,
                                                                context.GetRequiredService <ISyncPolicy>()),
                                                            context.GetRequiredService <IMetricsClient>()));

            services.AddSingleton <IConversationService>(context =>
                                                         new ConversationServiceMetricsDecorator(
                                                             new ConversationService(
                                                                 context.GetRequiredService <IConversationsStore>(),
                                                                 context.GetRequiredService <ILogger <ConversationService> >(),
                                                                 context.GetRequiredService <INotificationService>()),
                                                             context.GetRequiredService <IMetricsClient>()));

            services.AddLogging();
            services.AddMvc();
        }
コード例 #3
0
 public void TestInitialize()
 {
     store = new AzureTableMessagesStore(tableMock.Object);
 }