// 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(); }
public IoTHubTransmitter(IOptions <IoTHubSettings> iotHubSettings, ILogger <IoTHubTransmitter> logger) { _iotHubSettings = iotHubSettings.Value ?? throw new ArgumentNullException(nameof(iotHubSettings)); _logger = logger; }
public MessagingService(IoTHubSettings iotHubSettings) { _iotHubSettings = iotHubSettings; _iotHubServiceClient = ServiceClient.CreateFromConnectionString(_iotHubSettings.ServiceClientConnectionString); }