// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { var connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING") ?? Configuration.GetConnectionString("DefaultConnection"); //services.Configure<ForwardedHeadersOptions>(options => //{ // options.ForwardedHeaders = // ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; // //options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("::ffff:100.64.0.0"), 106)); //}); //services.AddDbContext<UfcContextLite>(options => options.UseSqlite("data source=.\\UfcSqlite.sqlite")); services.AddMvc(options => { options.Conventions.Add(new ApiExplorerIgnores()); //options.Filters.Add(new FluentValidateAttribute()); options.OutputFormatters.RemoveType <TextOutputFormatter>(); options.OutputFormatters.RemoveType <HttpNoContentOutputFormatter>(); }) .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; //options.SerializerSettings.Formatting = Formatting.Indented; }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSingleton <IFileProvider>( new PhysicalFileProvider(Directory.GetCurrentDirectory())); services.AddCors(options => { options.AddPolicy(corsPolicy, builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Fight Search Api", Version = "v1" }); }); services.Configure <ImagePaths>(Configuration.GetSection("ImagePaths")); services.AddEntityFrameworkSqlServer(); //string connectionString = Configuration.GetConnectionString("DefaultConnection"); //services.AddDbContext<UfcContext>(options => //{ // //string connectionString = Configuration.GetConnectionString("DefaultConnection"); // options.UseSqlServer(connectionString); // //IHostingEnvironment hostingEnvironment = SettingsProvider.HostingEnvironment; // //ILoggerFactory loggerFactory = SettingsProvider.LoggerFactory; // // Enables application data to be included in exception messages, logging, etc. This can include the values assigned to properties of your entity instances, // // parameter values for commands being sent to the database, and other such data. You should only enable this flag // // if you have the appropriate security measures in place based on the sensitivity of this data. // options.EnableSensitiveDataLogging(SettingsProvider.HostingEnvironment.IsDevelopment()); // //Enables detailed errors when handling of data value exceptions that occur during processing of store query results. Such errors // //most often occur due to misconfiguration of entity properties. E.g. If a property is configured to be of type // //'int', but the underlying data in the store is actually of type 'string', then an exception will be generated // //at runtime during processing of the data value. When this option is enabled and a data error is encountered, the // //generated exception will include details of the specific entity property that generated the error. // //Enabling this option incurs a small performance overhead during query execution. // options.EnableDetailedErrors(SettingsProvider.HostingEnvironment.IsDevelopment()); // //options.UseLoggerFactory(GetConsoleLoggerFactory()); // options.UseLoggerFactory(SettingsProvider.LoggerFactory); // options.ConfigureWarnings(warn => { warn.Default(WarningBehavior.Log); }); //}); // config sqlite DbContextOptionsBuilder <UfcContextLite> optionsBuilder = new DbContextOptionsBuilder <UfcContextLite>() .UseSqlite(Configuration.GetConnectionString("SqLiteDefaultConnection")); UfcContextLite context = new UfcContextLite(optionsBuilder.Options); context.Database.EnsureCreated(); services.AddSingleton(optionsBuilder.Options); //services.AddDbContextPool<UfcContextLite>(options => options.UseSqlite(Configuration.GetConnectionString("SqLiteDefaultConnection"))); services.AddDbContextPool <UfcContextLite>(options => options.UseSqlite(Configuration.GetConnectionString("SqLiteDefaultConnection"))); services.AddScoped <UfcContextLite>(); //services.AddSingleton<UfcContextLite>(context); //services.AddDbContext<UfcContext>(options => options.UseSqlServer(connectionString)); //services.AddScoped<IFightSearchEntities, UfcContext>(); //services.AddScoped<IVisitorTrackingService, VisitorTrackingService>(); services.AddScoped <IVisitorTrackingService, VisitorTrackingServiceSqLite>(); //services.AddScoped<ISearchService, SearchService>(); services.AddScoped <ISearchService, SearchServiceSqLite>(); //services.AddScoped<IFighterNameService, FighterNameService>(); services.AddScoped <IFighterNameService, FighterNameServiceSqLite>(); //services.AddProgressiveWebApp(new PwaOptions //{ // RegisterServiceWorker = false, // RegisterWebmanifest = false, // OfflineRoute = "offline" //}); }
//public SqLiteMigration(UfcContext ufcContext, UfcContextLite ufcContextLite) public SqLiteMigration(UfcContext ufcContext, ILogger <SqLiteMigration> logger, UfcContextLite ufcContextLite) { _ufcContext = ufcContext; _logger = logger; _ufcContextLite = ufcContextLite; }
public FighterNameServiceSqLite(IMemoryCache memoryCache, UfcContextLite ufcContextLite) { _memoryCache = memoryCache; _ufcContextLite = ufcContextLite; _provider = CultureInfo.InvariantCulture; }
public VisitorTrackingServiceSqLite(UfcContextLite ufcContextLite) { _ufcContextLite = ufcContextLite; _provider = CultureInfo.InvariantCulture; }
public static async Task Main(string[] args) { Logger logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); Console.WriteLine("Hello World!"); IHost host = new HostBuilder() .UseNLog() .ConfigureHostConfiguration(config => { //command line if (args != null) { config.AddCommandLine(args); } }) .ConfigureAppConfiguration((hostContext, config) => { string currentDirectory = Directory.GetCurrentDirectory(); string jsonFile = Path.Combine(currentDirectory, "appsettings.json"); if (!File.Exists(jsonFile)) { currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", ""); } config.SetBasePath(currentDirectory); config.AddJsonFile("appsettings.json", true); config.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", true); config.AddEnvironmentVariables(); if (args != null) { config.AddCommandLine(args); } Configuration = config.Build(); Console.WriteLine(hostContext.HostingEnvironment.EnvironmentName); string connectionString = Configuration.GetConnectionString("DefaultConnection"); //AppSettingOptions appSettings = Configuration.GetSection("AppSettingOptions").Get<AppSettingOptions>(); }) .ConfigureServices((hostContext, services) => { services.AddEntityFrameworkSqlServer() .AddDbContext <UfcContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); options.EnableSensitiveDataLogging(hostContext.HostingEnvironment.IsDevelopment()); options.EnableDetailedErrors(hostContext.HostingEnvironment.IsDevelopment()); //options.UseLoggerFactory(GetConsoleLoggerFactory()); //ServiceProvider x = services.BuildServiceProvider(); options.UseLoggerFactory(GetNLogLoggerFactory()); }); services.AddTransient <UfcContext>(); //services.AddScoped<IFightSearchEntities, UfcContext>(); // Database DbContextOptionsBuilder <UfcContextLite> optionsBuilder = new DbContextOptionsBuilder <UfcContextLite>() .UseSqlite(Configuration.GetConnectionString("SqLiteDefaultConnection")); UfcContextLite context = new UfcContextLite(optionsBuilder.Options); context.Database.EnsureCreated(); services.AddSingleton(optionsBuilder.Options); services.AddDbContextPool <UfcContextLite>(options => options.UseSqlite(Configuration.GetConnectionString("SqLiteDefaultConnection"))); services.AddSingleton <UfcContextLite>(context); services.AddHostedService <PortSqlServerToSqlLiteHostedService>(); services.AddTransient <ISqLiteMigration, SqLiteMigration>(); ServiceProvider = services.BuildServiceProvider(); }) .ConfigureLogging((hostContext, configLogging) => { configLogging.ClearProviders(); // use nLog //configLogging.AddNLog(new NLogProviderOptions {CaptureMessageTemplates = true, CaptureMessageProperties = true}); //configLogging.AddConsole(); //configLogging.AddNLog(new NLogProviderOptions {CaptureMessageTemplates = true, CaptureMessageProperties = true}); //LogFactory factory = NLogBuilder.ConfigureNLog("nlog.config"); LogFactory test = NLogBuilder.ConfigureNLog("nlog.config"); //configLogging.AddNLog(new NLogProviderOptions {CaptureMessageTemplates = true, CaptureMessageProperties = true}); //NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = Configuration; LogManager.Configuration.Variables["connectionString"] = Configuration.GetConnectionString("DefaultConnection"); //var loggerFactory = ServiceProvider.GetService<ILoggerFactory>(); //loggerFactory.AddNLog(); //loggerFactory.ConfigureNLog("nlog.config"); }) .UseConsoleLifetime() .Build(); using (host) { logger.Info("startinng ."); CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken token = cts.Token; await host.StartAsync(token); await host.WaitForShutdownAsync(token); logger.Info("stoppig ."); // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) LogManager.Shutdown(); } }
public SearchServiceSqLite(IOptions <ImagePaths> imagePathSettings, UfcContextLite ufcContextLite) { _imagePathSettings = imagePathSettings; _ufcContextLite = ufcContextLite; _provider = CultureInfo.InvariantCulture; }