protected void Application_Start(object sender, EventArgs e) { ServiceConfig.ConfigureServices(); IUnityContainer container = new UnityContainer(); container.LoadConfiguration(); container.RegisterInstance(DataServiceProvider.DataService); GlobalConfiguration.Configure(configuration => ODataConfig.Configure(configuration, container)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { /* * services.AddDbContext<ApplicationDbContext>(options => * options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); * * services.AddIdentity<ApplicationUser, IdentityRole>() * .AddEntityFrameworkStores<ApplicationDbContext>() * .AddDefaultTokenProviders(); */ // Add application services. services.AddTransient <IEmailSender, EmailSender>(); ServiceConfig.ConfigureServices(services); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { Configuration.LoadConfiguration(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddControllers().AddNewtonsoftJson(c => { c.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; c.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); }).AddJsonOptions(c => { c.JsonSerializerOptions.IgnoreNullValues = true; c.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); });; services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "TapegandoFogoBicho.Controller", Version = "v1" }); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); }); RepositoryConfig.ConfigureServices(services); ExecutorConfig.ConfigureServices(services); ServiceConfig.ConfigureServices(services); MqttClient client = new MqttClient("broker.shiftr.io"); client.MqttMsgPublishReceived += (object o, MqttMsgPublishEventArgs m) => { MqttExecutor mqttExecutor = new MqttExecutor(new MeasurementRepository(new RepositoryHelper())); mqttExecutor.Execute(new MqttRequest { measurement = JsonConvert.DeserializeObject <MeasurementModel>(Encoding.UTF8.GetString(m.Message, 0, m.Message.Length)) }); }; string clientId = MqttConnection.MqttClient; string username = MqttConnection.MqttUser; string password = MqttConnection.MqttPassword; client.Connect(clientId, username, password); client.Subscribe(new string[] { "/FireWatcher" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); }