// This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
     //Paging.ConfigureServices(services);
     SwaggerConfig.ConfigureServices(services);
     AppIDConfigUrl.ConfigureServices(services);
     //IMapperConfig.ImapperConfigService(services);
     //ConfigServiceFluentValidation.ConfigureServices(services);
     services.AddDbContext <ChoThueXeContext>(options =>
                                              options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
     RepositoryConfig.ConfigureServices(services);
 }
Ejemplo n.º 2
0
        // 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 });
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //register services
            services.AddMvc();
            MappingConfig.ConfigureServices(services);
            RepositoryConfig.ConfigureServices(services);
            EntityFrameworkConfig.ConfigureServices(services, Configuration);

            services.AddCors(o => o.AddPolicy(AllowAllOriginsPolicy, builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            //use default json contract resolver due to prevent lowercase transformation
            services.AddMvc().AddJsonOptions(p => p.SerializerSettings.ContractResolver = new DefaultContractResolver());
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            CORSConfig.ConfigureServices(services);
            services.AddMvcCore()
            .AddAuthorization()
            .AddJsonFormatters();

            services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority            = endponit + tenantId;
                options.RequireHttpsMetadata = false;
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            Paging.ConfigureServices(services);
            SwaggerConfig.ConfigureServices(services);
            AppIDConfigUrl.ConfigureServices(services);

            services.AddDbContext <ChoThueXeContext>(options =>
                                                     options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            RepositoryConfig.ConfigureServices(services);
        }