// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var queuePublisher = new QueueClient(publisherConnectionString, Queues.GeneralCommand);

            services.AddTransient <IQueueMessengerClient>(sp =>
                                                          new MessengerClient(queuePublisher));

            var queueListener = new QueueClient(subscriberConnectionString, Queues.GeneralCommand);

            services.AddTransient <IQueueObserverClient>(sp =>
                                                         new ObserverClient(queueListener));

            var topicBus = new TopicClient(publisherConnectionString, Topics.GeneralInfo);

            services.AddTransient <ITopicMessengerClient>(sp =>
                                                          new MessengerClient(topicBus));

            var subscriberBus = new SubscriptionClient(subscriberConnectionString, Topics.GeneralInfo, "gis");

            services.AddSingleton <ITopicObserverClient>((sp) =>
            {
                var observer = new ObserverClient(subscriberBus, false);
                observer.RegisterForLogNotifications(LogProcessor);
                return(observer);
            });

            // START the Logger, connects to Kibana //
            logger = new LogManager(Configuration["ElasticConfiguration:Uri"]);
            logger.Log(new LogEntry {
                Id = 1, Title = "Administration Management App initializing.", Type = LogType.Information.ToString()
            });
            services.AddSingleton <Universal.Contracts.Logging.ILogger>(logger);

            // ADD a default data storage mechanism //
            services.AddDbContext <ApplicationDbContext>(options => options.UseInMemoryDatabase("Messages"));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var container  = services.BuildServiceProvider();
            var repository = new MessageRepository(
                container.GetService <ApplicationDbContext>());

            services.AddSingleton <MessageRepository>(repository);

            services.AddSingleton <MessagingService>();

            services.AddSingleton <IFileRepository>(fr =>
            {
                return(new AzureFileRepository(
                           new AzureFileReader(
                               Configuration["UploadStorageAcctName"],
                               Configuration["StorageAccountKey"],
                               "gis-uploads")));
            });

            services.AddSingleton <FileService>();

            services.AddSingleton <MessageHub>();
            services.AddSignalR();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            logger = new LogManager(Configuration["ElasticConfiguration:Uri"]);
            logger.Log(new LogEntry {
                Id = 1, Title = "Administration Management App initializing.", Type = LogType.Information.ToString()
            });
            services.AddSingleton <Universal.Contracts.Logging.ILogger>(logger);

            var serviceBus = new QueueClient(ServiceBusConnectionString, Queues.GeneralCommand);

            services.AddTransient <IQueueMessengerClient>(sp =>
                                                          new MessengerClient(serviceBus));

            var qObserver = new QueueClient(subscriberConnectionString, Queues.GeneralCommand);

            services.AddTransient <IQueueObserverClient>(sp =>
            {
                var observer = new ObserverClient(qObserver);
                observer.RegisterForLogNotifications(LogProcessor);
                return(observer);
            });

            var topicBus = new TopicClient(ServiceBusConnectionString, Topics.GeneralInfo);

            services.AddTransient <ITopicMessengerClient>(sp =>
                                                          new MessengerClient(topicBus));

            var subscriberBus = new SubscriptionClient(ServiceBusConnectionString, Topics.GeneralInfo, "gis");

            services.AddSingleton <ITopicObserverClient>(sp =>
            {
                var observer = new ObserverClient(subscriberBus, false);
                observer.RegisterForLogNotifications(LogProcessor);
                return(observer);
            });

            services.AddSingleton <LayerTileCacheAccessor>(new LayerTileCacheAccessor(
                                                               () => new SimpleTileCacheStorage <ITransformedTile>(),
                                                               () => new SimpleTileCacheStorage <ITile>()));

            services.AddSingleton <ProcessingService>();
            services.AddSingleton <MessageRepository>(new MessageRepository());

            var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/layers"));
            var serverIp     = Configuration["ServerAddress:Https"];

            services.AddSingleton <ILayerInitializationService>(new LayerInitializationFileService(fileProvider, serverIp));

            services.AddTransient <Generator>();

            services.AddTransient <TileRetrieverService>();

            services.AddSingleton <IFileProvider>(fileProvider);

            services.AddSingleton <IFileRepository>(fr =>
            {
                return(new AzureFileRepository(
                           new AzureFileReader(
                               Configuration["AzureFileStorage:UploadStorageAcctName"],
                               Configuration["AzureFileStorage:StorageAccountKey"],
                               Configuration["AzureFileStorage:FileStoreName"])));
            });

            services.AddSingleton <ITileCacheStorage <ITile> >(new SimpleTileCacheStorage <ITile>());
            services.AddSingleton <ITileCacheStorage <ITransformedTile> >(new SimpleTileCacheStorage <ITransformedTile>());
            services.AddTransient <ITileContext>((sp) =>
            {
                return(new SimpleTileContext()
                {
                    MaxZoom = 14,
                    Buffer = 64,
                    Extent = 4096,
                    Tolerance = 3
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // Adding Cross Origin Request requires the AddCors() call in the ConfigureServices, from this: //
            // https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-2.2
            services.AddCors(options =>
            {
                options.AddDefaultPolicy(
                    builder =>
                {
                    builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
                });
            });

            // Build the container to allow for the registration of message receivers //
            var container = services.BuildServiceProvider();

            var processing = container.GetService <ProcessingService>();

            processing.RegisterNotificationHandlers(container.GetService <MessageRepository>(), container.GetService <IFileRepository>());
        }