Esempio n. 1
0
        public void RegisterServices(Container container)
        {
            Logger.RegisterWriter(new NLogAdapter());

            if (Settings.Current.EnableMetricsReporting)
            {
                container.RegisterSingleton <IMetricsClient>(() => new StatsDMetricsClient(Settings.Current.MetricsServerName, Settings.Current.MetricsServerPort, "ex"));
            }
            else
            {
                Log.Warn().Message("StatsD Metrics is NOT enabled.").Write();
            }

            if (Settings.Current.EnableRedis)
            {
                container.RegisterSingleton <ConnectionMultiplexer>(() => {
                    var multiplexer = ConnectionMultiplexer.Connect(Settings.Current.RedisConnectionString);
                    multiplexer.PreserveAsyncOrder = false;
                    return(multiplexer);
                });

                container.RegisterSingleton <ICacheClient, RedisHybridCacheClient>();
                container.RegisterSingleton <IQueue <EventPost> >(() => new RedisQueue <EventPost>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), behaviors: container.GetAllInstances <IQueueBehavior <EventPost> >()));
                container.RegisterSingleton <IQueue <EventUserDescription> >(() => new RedisQueue <EventUserDescription>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), behaviors: container.GetAllInstances <IQueueBehavior <EventUserDescription> >()));
                container.RegisterSingleton <IQueue <EventNotificationWorkItem> >(() => new RedisQueue <EventNotificationWorkItem>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), behaviors: container.GetAllInstances <IQueueBehavior <EventNotificationWorkItem> >()));
                container.RegisterSingleton <IQueue <WebHookNotification> >(() => new RedisQueue <WebHookNotification>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), behaviors: container.GetAllInstances <IQueueBehavior <WebHookNotification> >()));
                container.RegisterSingleton <IQueue <MailMessage> >(() => new RedisQueue <MailMessage>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), behaviors: container.GetAllInstances <IQueueBehavior <MailMessage> >()));
                container.RegisterSingleton <IQueue <StatusMessage> >(() => new RedisQueue <StatusMessage>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>()));
                container.RegisterSingleton <IQueue <WorkItemData> >(() => new RedisQueue <WorkItemData>(container.GetInstance <ConnectionMultiplexer>(), workItemTimeout: TimeSpan.FromHours(1), behaviors: container.GetAllInstances <IQueueBehavior <WorkItemData> >()));

                container.RegisterSingleton <IMessageBus>(() => new RedisMessageBus(container.GetInstance <ConnectionMultiplexer>().GetSubscriber(), serializer: container.GetInstance <ISerializer>()));
            }
            else
            {
                Log.Warn().Message("Redis is NOT enabled.").Write();
            }

            if (Settings.Current.EnableAzureStorage)
            {
                container.RegisterSingleton <IFileStorage>(new AzureFileStorage(Settings.Current.AzureStorageConnectionString, "ex-events"));
            }
            else
            {
                Log.Warn().Message("Azure Storage is NOT enabled.").Write();
            }

            var client = ExceptionlessClient.Default;

            container.RegisterSingleton <ICoreLastReferenceIdManager, ExceptionlessClientCoreLastReferenceIdManager>();
            container.RegisterSingleton <ExceptionlessClient>(() => client);

            client.Configuration.SetVersion(Settings.Current.Version);
            client.Register();
            container.AddBootstrapper <HttpConfiguration>(config => client.RegisterWebApi(config));
            client.Configuration.UseInMemoryStorage();
            client.Configuration.UseReferenceIds();
        }
Esempio n. 2
0
        public void RegisterServices(Container container)
        {
            if (Settings.Current.EnableMetricsReporting)
            {
                container.RegisterSingle <IMetricsClient>(() => new StatsDMetricsClient(Settings.Current.MetricsServerName, Settings.Current.MetricsServerPort, "ex"));
            }

            if (Settings.Current.EnableRedis)
            {
                var muxer = ConnectionMultiplexer.Connect(Settings.Current.RedisConnectionString);
                container.RegisterSingle(muxer);

                container.RegisterSingle <ICacheClient, RedisHybridCacheClient>();

                container.RegisterSingle <IQueue <EventPost> >(() => new RedisQueue <EventPost>(muxer, container.GetInstance <ISerializer>(), statName: MetricNames.PostsQueueSize, metrics: container.GetInstance <IMetricsClient>()));
                container.RegisterSingle <IQueue <EventUserDescription> >(() => new RedisQueue <EventUserDescription>(muxer, container.GetInstance <ISerializer>(), statName: MetricNames.EventsUserDescriptionQueueSize, metrics: container.GetInstance <IMetricsClient>()));
                container.RegisterSingle <IQueue <EventNotificationWorkItem> >(() => new RedisQueue <EventNotificationWorkItem>(muxer, container.GetInstance <ISerializer>(), statName: MetricNames.EventNotificationQueueSize, metrics: container.GetInstance <IMetricsClient>()));
                container.RegisterSingle <IQueue <WebHookNotification> >(() => new RedisQueue <WebHookNotification>(muxer, container.GetInstance <ISerializer>(), statName: MetricNames.WebHookQueueSize, metrics: container.GetInstance <IMetricsClient>()));
                container.RegisterSingle <IQueue <MailMessage> >(() => new RedisQueue <MailMessage>(muxer, container.GetInstance <ISerializer>(), statName: MetricNames.EmailsQueueSize, metrics: container.GetInstance <IMetricsClient>()));
                container.RegisterSingle <IQueue <StatusMessage> >(() => new RedisQueue <StatusMessage>(muxer, container.GetInstance <ISerializer>()));

                container.RegisterSingle <IMessageBus>(() => new RedisMessageBus(muxer.GetSubscriber(), serializer: container.GetInstance <ISerializer>()));
            }

            if (Settings.Current.EnableAzureStorage)
            {
                container.RegisterSingle <IFileStorage>(new AzureFileStorage(Settings.Current.AzureStorageConnectionString, "ex-events"));
            }

            var client = ExceptionlessClient.Default;

            container.RegisterSingle <ICoreLastReferenceIdManager, ExceptionlessClientCoreLastReferenceIdManager>();
            container.RegisterSingle <ExceptionlessClient>(() => client);

            client.Configuration.SetVersion(Settings.Current.Version);
            client.Register();
            container.AddBootstrapper <HttpConfiguration>(config => client.RegisterWebApi(config));
            client.Configuration.UseInMemoryStorage();
            client.Configuration.UseReferenceIds();
        }
Esempio n. 3
0
        public static void RegisterServices(Container container, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddNLog();
            var logger = loggerFactory.CreateLogger <Bootstrapper>();

            if (!String.IsNullOrEmpty(Settings.Current.GoogleGeocodingApiKey))
            {
                container.RegisterSingleton <IGeocodeService>(() => new GoogleGeocodeService(Settings.Current.GoogleGeocodingApiKey));
            }

            if (Settings.Current.EnableMetricsReporting)
            {
                container.RegisterSingleton <IMetricsClient>(() => new StatsDMetricsClient(Settings.Current.MetricsServerName, Settings.Current.MetricsServerPort, "ex"));
            }
            else
            {
                logger.Warn("StatsD Metrics is NOT enabled.");
            }

            if (Settings.Current.EnableRedis)
            {
                container.RegisterSingleton <ConnectionMultiplexer>(() => {
                    var multiplexer = ConnectionMultiplexer.Connect(Settings.Current.RedisConnectionString);
                    multiplexer.PreserveAsyncOrder = false;
                    return(multiplexer);
                });

                if (Settings.Current.HasAppScope)
                {
                    container.RegisterSingleton <ICacheClient>(() => new ScopedCacheClient(new RedisHybridCacheClient(container.GetInstance <ConnectionMultiplexer>()), Settings.Current.AppScope));
                }
                else
                {
                    container.RegisterSingleton <ICacheClient, RedisHybridCacheClient>();
                }

                if (Settings.Current.EnableSignalR)
                {
                    container.RegisterSingleton <IConnectionMapping, RedisConnectionMapping>();
                }

                container.RegisterSingleton <IQueue <EventPost> >(() => new RedisQueue <EventPost>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), GetQueueName <EventPost>(), behaviors: container.GetAllInstances <IQueueBehavior <EventPost> >()));
                container.RegisterSingleton <IQueue <EventUserDescription> >(() => new RedisQueue <EventUserDescription>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), GetQueueName <EventUserDescription>(), behaviors: container.GetAllInstances <IQueueBehavior <EventUserDescription> >()));
                container.RegisterSingleton <IQueue <EventNotificationWorkItem> >(() => new RedisQueue <EventNotificationWorkItem>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), GetQueueName <EventNotificationWorkItem>(), behaviors: container.GetAllInstances <IQueueBehavior <EventNotificationWorkItem> >()));
                container.RegisterSingleton <IQueue <WebHookNotification> >(() => new RedisQueue <WebHookNotification>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), GetQueueName <WebHookNotification>(), behaviors: container.GetAllInstances <IQueueBehavior <WebHookNotification> >()));
                container.RegisterSingleton <IQueue <MailMessage> >(() => new RedisQueue <MailMessage>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), GetQueueName <MailMessage>(), behaviors: container.GetAllInstances <IQueueBehavior <MailMessage> >()));
                container.RegisterSingleton <IQueue <WorkItemData> >(() => new RedisQueue <WorkItemData>(container.GetInstance <ConnectionMultiplexer>(), container.GetInstance <ISerializer>(), GetQueueName <WorkItemData>(), workItemTimeout: TimeSpan.FromHours(1), behaviors: container.GetAllInstances <IQueueBehavior <WorkItemData> >()));

                container.RegisterSingleton <IMessageBus>(() => new RedisMessageBus(container.GetInstance <ConnectionMultiplexer>().GetSubscriber(), $"{Settings.Current.AppScopePrefix}messages", container.GetInstance <ISerializer>()));
            }
            else
            {
                logger.Warn("Redis is NOT enabled.");
            }

            if (Settings.Current.EnableAzureStorage)
            {
                container.RegisterSingleton <IFileStorage>(new AzureFileStorage(Settings.Current.AzureStorageConnectionString, $"{Settings.Current.AppScopePrefix}ex-events"));
            }
            else
            {
                logger.Warn("Azure Storage is NOT enabled.");
            }

            var client = ExceptionlessClient.Default;

            container.RegisterSingleton <ICoreLastReferenceIdManager, ExceptionlessClientCoreLastReferenceIdManager>();
            container.RegisterSingleton <ExceptionlessClient>(() => client);

            client.Configuration.UpdateSettingsWhenIdleInterval = TimeSpan.FromSeconds(15);
            client.Configuration.SetVersion(Settings.Current.Version);
            if (String.IsNullOrEmpty(Settings.Current.InternalProjectId))
            {
                client.Configuration.Enabled = false;
            }

            client.Register();
            container.AddBootstrapper <HttpConfiguration>(config => client.RegisterWebApi(config));
            client.Configuration.UseInMemoryStorage();
            client.Configuration.UseReferenceIds();
        }