public void ConfigureServices(IServiceCollection services) { // Set a variable in the gdc which is be used in NLog.config for the // base path of our app: ${gdc:item=appbasepath} string logfilesPath = GMFileAccess.GetFullPath(configuration["AppSettings:LogfilesPath"]); GlobalDiagnosticsContext.Set("logfilesPath", logfilesPath); // Create an instance of NLog.Logger manually here since it is not available // from dependency injection yet. logger = LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger(); logger.Info("Just set value in GDC for NLog and created NLog.Logger instance"); logger.Info("Modify some AppSettings"); services.AddOptions(); services.Configure <AppSettings>(configuration.GetSection("AppSettings")); services.Configure <AppSettings>(myOptions => { // Modify the configuration path options to be full paths. myOptions.LogfilesPath = GMFileAccess.GetFullPath(myOptions.LogfilesPath); myOptions.DatafilesPath = GMFileAccess.GetFullPath(myOptions.DatafilesPath); myOptions.TestfilesPath = GMFileAccess.GetFullPath(myOptions.TestfilesPath); Console.WriteLine("Datafile path = " + myOptions.DatafilesPath); }); logger.Info("Add ApplicationDbContext"); services.AddTransient <dBOperations>(); // We will be able to access ApplicationDbContext in a controller with: // public MyController(ApplicationDbContext context) { ... } services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( configuration["AppSettings:ConnectionString"] //sqlServerOptions => sqlServerOptions.MigrationsAssembly("DatabaseAccess_Lib") //sqlServerOptions => sqlServerOptions.MigrationsAssembly("WebApp") )); logger.Info("Add Add Authentication"); //ConfigureAuthenticationServices(services); ConfigureAuthenticationServices(services, logger); logger.Info("Add MVC"); services.AddMvc() // The ContractResolver option is to prevent the case of Json field names // being changed when retrieved by client. // https://codeopinion.com/asp-net-core-mvc-json-output-camelcase-pascalcase/ .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()) .AddXmlSerializerFormatters(); logger.Info("Enable Feature Folders"); // This enables the use of "Feature Folders". // https://scottsauber.com/2016/04/25/feature-folder-structure-in-asp-net-core/ services.Configure <RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new FeatureLocationExpander()); }); //logger.Info("Add SPA static files"); //// In production, the Angular files will be served from this directory //services.AddSpaStaticFiles(configuration => //{ // configuration.RootPath = "../../FrontEnd/ClientApp/dist"; // //configuration.RootPath = "ClientApp/dist"; //}); logger.Info("Add Application services"); bool UseDatabaseStubs = (configuration["AppSettings:UseDatabaseStubs"] == "True") ? true : false; AddApplicationServices(services, logger, UseDatabaseStubs); services.AddSingleton(configuration); }
private static void ConfigureServices(IServiceCollection services) { var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); // add configured instance of logging services.AddSingleton(new LoggerFactory() .AddConsole() .AddDebug()); // add logging services.AddLogging(); // build configuration // appsettings.json is copied to the output folder during the build. // Otherwise, we would need to set appsettingsdir as follows: // string appsettingsdir = Directory.GetCurrentDirectory() + @"\..\..\.."; // Location of appsettings.json string appsettingsdir = Directory.GetCurrentDirectory(); string devSettingFile = $"appsettings.{environmentName}.json"; // Find path to the _SECRETS folder string secrets = GMFileAccess.FindParentFolderWithName("_SECRETS"); // If it exists look there for environment settings file. if (secrets != null) { devSettingFile = Path.Combine(secrets, $"appsettings.{environmentName}.json"); } var configuration = new ConfigurationBuilder() // TODO - The following path will only work in development. // It isn't yet decided how WorkflowApp will run in production. // Will it be a separate .EXE or a .LIB loaded by WebApp? .SetBasePath(appsettingsdir) .AddJsonFile("appsettings.json", false) .AddJsonFile(devSettingFile, optional: true) .Build(); services.AddOptions(); services.Configure <AppSettings>(configuration.GetSection("AppSettings")); services.Configure <AppSettings>(myOptions => { // Modify paths to be full paths. myOptions.DatafilesPath = GMFileAccess.GetFullPath(myOptions.DatafilesPath); myOptions.TestfilesPath = GMFileAccess.GetFullPath(myOptions.TestfilesPath); myOptions.GoogleApplicationCredentials = GMFileAccess.GetFullPath(myOptions.GoogleApplicationCredentials); }); // add services //services.AddTransient<IOptions<AppSettings>>(); services.AddTransient <ApplicationDbContext>(); services.AddTransient <dBOperations>(); services.AddTransient <RecordingProcess>(); services.AddTransient <TranscribeAudio>(); services.AddTransient <TranscriptProcess>(); //services.AddTransient<ILoadTranscript, LoadTranscript_Stub>(); services.AddTransient <AddtagsRepository>(); services.AddTransient <FixasrRepository>(); services.AddTransient <IMeetingRepository, MeetingRepository_Stub>(); services.AddTransient <IGovBodyRepository, GovBodyRepository_Stub>(); services.AddTransient <WF_RetrieveOnlineFiles>(); services.AddTransient <WF_ProcessReceivedFiles>(); services.AddTransient <WF_ProcessRecordings>(); services.AddTransient <WF_ProcessTranscripts>(); services.AddTransient <WF_ProcessTagged>(); services.AddTransient <WF_ProcessProofread>(); services.AddTransient <WF_LoadDatabase>(); // add app services.AddTransient <WorkflowController>(); }