public CrossConnectionManager(SimpleForumRepository repository, CrossConnectionClient client, IOptionsSnapshot <SimpleForumConfig> config) { _repository = repository; _client = client; _config = config.Value; }
/// <summary> /// Creates an instance of <see cref="SimpleForumRepository"/> /// </summary> /// <param name="context">The database context for which to initialise the repository with</param> /// <param name="emailService">The email service used to send emails</param> /// <param name="config">The filename of settings file to use</param> /// <param name="contextAccessor">Used to access the HTTP context</param> public SimpleForumRepository(ApplicationDbContext context, IEmailService emailService, IOptionsSnapshot <SimpleForumConfig> config, IHttpContextAccessor contextAccessor) { _context = context; _emailService = emailService; _config = config.Value; _httpContext = contextAccessor.HttpContext; }
// Creates a host builder for the given service public static IHostBuilder CreateHostBuilder <Startup>(string[] args, Service service) where Startup : class { // Creates file directories if needed CreateDirectories(); // Sets arguments, config and port values ServerArguments arguments = ArgumentParser.ParseArguments(args); string path = arguments.Config ?? Directory.GetParent(Directory.GetCurrentDirectory()).FullName + "/SimpleForumConfig.json"; SimpleForumConfig config = new SimpleForumConfig(); new ConfigurationBuilder() .AddJsonFile(path, false) .Build() .Bind(config); int port = service switch { Service.Web => config.WebPort, Service.Api => config.ApiPort, Service.CrossConnect => config.CrossConnectionPort, _ => throw new ArgumentOutOfRangeException(nameof(service), service, null) }; // Creates HostBuilder return(Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostingContext, configurationBuilder) => { configurationBuilder.AddJsonFile(path, false, true); configurationBuilder.AddCommandLine(args); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseUrls($"http://localhost:{arguments.Port ?? port}"); webBuilder.UseStartup <Startup>(); })); }