Example #1
0
        public static void ConfigureAppSettings(this IServiceCollection services, IConfiguration configuration)
        {
            var azureAdGraphConfiguration = new AzureAdGraphSettings()
            {
                AzureAdB2CTenant      = configuration["AzureAdGraph:AzureAdB2CTenant"],
                ClientId              = configuration["AzureAdGraph:ClientId"],
                ClientSecret          = configuration["AzureAdGraph:ClientSecret"],
                PolicyName            = configuration["AzureAdGraph:PolicyName"],
                ApiUrl                = configuration["AzureAdGraph:ApiUrl"],
                ApiVersion            = configuration["AzureAdGraph:ApiVersion"],
                ExtensionsAppClientId = configuration["AzureAdGraph:ExtensionsAppClientId"]
            };

            services.AddSingleton(azureAdGraphConfiguration);

            var azureAdB2CSettings = new AzureAdB2CSettings()
            {
                ClientId = configuration["AzureAdB2C:ClientId"],
                Tenant   = configuration["AzureAdB2C:Tenant"],
                Policy   = configuration["AzureAdB2C:Policy"]
            };

            services.AddSingleton(azureAdB2CSettings);

            var microsoftGraphSettings = new MicrosoftGraphSettings()
            {
                AzureAdB2CTenant = configuration["MicrosoftGraph:AzureAdB2CTenant"],
                ClientId         = configuration["MicrosoftGraph:ClientId"],
                ClientSecret     = configuration["MicrosoftGraph:ClientSecret"],
                ApiUrl           = configuration["MicrosoftGraph:ApiUrl"],
                ApiVersion       = configuration["MicrosoftGraph:ApiVersion"]
            };

            services.AddSingleton(microsoftGraphSettings);

            var cosmosDbSettings = new CosmosDbSettings()
            {
                Account      = configuration["CosmosDb:Account"],
                Key          = configuration["CosmosDb:Key"],
                DatabaseName = configuration["CosmosDb:DatabaseName"],
                TutorLearningProfilesContainerName = configuration["CosmosDb:TutorLearningProfilesContainerName"],
                ChatMessagesContainerName          = configuration["CosmosDb:ChatMessagesContainerName"]
            };

            services.AddSingleton(cosmosDbSettings);

            var notificationHubSettings = new NotificationHubSettings()
            {
                HubName = configuration["NotificationHub:HubName"],
                HubDefaultFullSharedAccessSignature = configuration["NotificationHub:HubDefaultFullSharedAccessSignature"]
            };

            services.AddSingleton(notificationHubSettings);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var azureAdB2CSettings = new AzureAdB2CSettings()
            {
                ClientId = Configuration["AzureAdB2C:ClientId"],
                Tenant   = Configuration["AzureAdB2C:Tenant"],
                Policy   = Configuration["AzureAdB2C:Policy"]
            };

            services.AddAuthentication(options =>
            {
                options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(jwtOptions =>
            {
                jwtOptions.Authority = $"https://login.microsoftonline.com/tfp/{azureAdB2CSettings.Tenant}/{azureAdB2CSettings.Policy}/v2.0/";
                jwtOptions.Audience  = azureAdB2CSettings.ClientId;
                jwtOptions.Events    = new JwtBearerEvents
                {
                    OnAuthenticationFailed = AuthenticationFailed
                };
            });

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

            var tableStorageSettings = new TableStorageSettings()
            {
                ConnectionString = Configuration["TableStorageConfiguration:ConnectionString"]
            };

            services.AddSingleton(tableStorageSettings);

            var messagingSettings = new IoTHubSettings()
            {
                ServiceClientConnectionString = Configuration["Messaging:ServiceClientConnectionString"]
            };

            services.AddSingleton(messagingSettings);

            services.AddSingleton <ISensorDataService <SensorData>, SensorDataService>();
            services.AddSingleton(typeof(ITableStorageService <TemperatureEntity>), typeof(TemperatureTableStorageService));
            services.AddSingleton(typeof(ITableStorageService <HumidityEntity>), typeof(HumidityTableStorageService));
            services.AddSingleton <IMessagingService, MessagingService>();

            AutoMapperConfiguration.Configure();
        }