123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using InitQ;
- using log4net;
- using log4net.Config;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.HttpsPolicy;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- using Microsoft.Extensions.Logging;
- using Microsoft.OpenApi.Models;
- using Ropin.Environmentally.VideoService.service;
- using Ropin.Environmentally.VideoService.Subscribe;
- using Ropin.Inspection.Common.Helper;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Repository;
- using Ropin.Inspection.Repository.MTN;
- using Ropin.Inspection.Repository.MTN.Interface;
- using Ropin.Inspection.Repository.SYS;
- using Ropin.Inspection.Repository.SYS.Interface;
- using Ropin.Inspection.Repository.VMC;
- using Ropin.Inspection.Repository.VMC.Interface;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Threading.Tasks;
- namespace Ropin.Environmentally.VideoService
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- var logRepo = LogManager.GetRepository(Assembly.GetEntryAssembly());
- XmlConfigurator.Configure(logRepo, new FileInfo("log4net.config"));
- }
- public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddSingleton(new Appsettings(Configuration));
- services.AddHttpClient();
- services.AddControllersWithViews();
- services.AddControllers();
- #region 配置文件
- var rabbitMQ = Configuration.GetSection("RabbitMQ").Get<RabbitMQModel>();
- services.AddSingleton<RabbitMQModel>(rabbitMQ);
- #endregion
- #region
- services.AddTransient<IVMCDevCameraRepository, VMCDevCameraRepository>();
- services.AddTransient<ITbdmCodeDetailRepository, TbdmCodeDetailRepository>();
- services.AddTransient<ImtnAlarmShadowRecordRepository, mtnAlarmShadowRecordRepository>();
- services.AddTransient<ITsysMessageFileRepository, TsysMessageFileRepository>();
- #endregion
- services.AddHostedService<RabbitMQVideoService>();
- //services.AddInitQ(m =>
- //{
- // m.SuspendTime = 1000;
- // m.ConnectionString = Configuration["ConnectionSetting:RedisConnection"];
- // m.ListSubscribe = new List<Type>() { typeof(RedisSubscribeBoxno), typeof(RedisIntervalSubscribeBoxno) };
- // m.ShowLog = false;
- //});
- services.AddNodeServices();
- services.AddSignalR();
- var connectionString = Configuration["ConnectionSetting:MySqlConnection"];
- ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
- services.AddDbContext<InspectionDbContext>(options =>
- options.UseMySql(connectionString, serverVersion));
- //但很多场景下Scoped又不能满足我们,这时候就需要注入一个Singleton的DBContext的工厂方法
- services.AddSingleton<Func<InspectionDbContext>>(() =>
- {
- var optionsBuilder = new DbContextOptionsBuilder<InspectionDbContext>();
- optionsBuilder.UseMySql(connectionString, serverVersion);
- //如果有其他依赖的话,可以通过provider.GetService<XX>()来获取
- return new InspectionDbContext(optionsBuilder.Options);
- });
- services.AddSwaggerGen(c =>
- {
- c.SwaggerDoc("v1", new OpenApiInfo { Title = "Ropin.Environmentally.VideoService", Version = "v1" });
- });
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- app.UseSwagger();
- app.UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "Ropin.Environmentally.VideoService v1"));
- }
- app.UseHttpsRedirection();
- app.UseRouting();
- app.UseAuthorization();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllers();
- });
- }
- }
- }
|