// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var restApiConfigSection = Configuration.GetSection("RestApiConfig"); RestApiConfig restApiConfig = restApiConfigSection.Get <RestApiConfig>(); services.AddSingleton(restApiConfig); var blobStorageConfigSection = Configuration.GetSection("BlobStorageConfig"); BlobStorageConfig blobStorageConfig = blobStorageConfigSection.Get <BlobStorageConfig>(); services.AddSingleton(blobStorageConfig); var jwtConfigSection = Configuration.GetSection("JwtSettings"); JWTConfig jWTConfig = jwtConfigSection.Get <JWTConfig>(); jWTConfig.CreateSecurityKey(); services.AddSingleton(jWTConfig); // https://code-maze.com/create-pdf-dotnetcore/ services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#basic-usage services.AddHttpClient(); services.AddScoped <ServiceRepository>(); services.AddDbContext <FrontEndContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbConnectionString"))); services.AddDefaultIdentity <FrontEndUser>(options => options.SignIn.RequireConfirmedAccount = false) .AddRoles <IdentityRole>() .AddEntityFrameworkStores <FrontEndContext>(); services.AddRazorPages(); services.AddControllersWithViews(); }
public void Should_Initialize_ValidDefaults_Test() { var endpoint = new RestApiConfig(); Assert.IsTrue(endpoint.BaseUri.Equals("hacker-news.firebaseio.com")); Assert.IsTrue(endpoint.ApiVersion.Equals("v0")); Assert.IsTrue(endpoint.IsSecure.Equals(true)); }
public void AsIndexEndpointUrl_Should_Return_Valid_IndexUri( [Values("topstories", "newstories", "beststories")] string endpointName) { var endpoint = new RestApiConfig(); var indexUrl = endpoint.AsIndexEndpointUrl(endpointName); Assert.AreEqual(indexUrl.AbsoluteUri, $"https://hacker-news.firebaseio.com/v0/{endpointName}.json"); }
public void AsItemEndpointUrl_Should_Return_Valid_IndexUri( [Values("1", "22015", "32043")] int id ) { var endpoint = new RestApiConfig(); var itemUrl = endpoint.AsItemEndpointUrl(id); Assert.AreEqual(itemUrl.AbsoluteUri, $"https://hacker-news.firebaseio.com/v0/item/{id}.json"); }
public void AsItemEndpointUrl_With_Id_Less_Than_One_Should_Throw_ArgumentOutOfRangeException( [Values("0", "-1", "-32043")] int negativeId) { var endpoint = new RestApiConfig(); ArgumentOutOfRangeException ex = Assert.Throws <ArgumentOutOfRangeException>( delegate { endpoint.AsItemEndpointUrl(negativeId); }); Assert.That(ex.ParamName, Is.EqualTo("id")); }
public void AsIndexEndpointUrl_With_Null_ApiVersion_Should_Throw_ArgumentNullException() { var endpoint = new RestApiConfig { ApiVersion = null }; ArgumentNullException ex = Assert.Throws <ArgumentNullException>( delegate { endpoint.AsIndexEndpointUrl("topstories"); }); Assert.That(ex.ParamName, Is.EqualTo(nameof(endpoint.ApiVersion))); }
public void AsIndexEndpointUrl_With_Null_BaseUri_Should_Throw_ArgumentNullException() { var endpoint = new RestApiConfig { BaseUri = null }; ArgumentNullException ex = Assert.Throws <ArgumentNullException>( delegate { endpoint.AsIndexEndpointUrl("test"); }); Assert.That(ex.ParamName, Is.EqualTo(nameof(endpoint.BaseUri))); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddHttpClient(); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); // wiring up application specific dependencies var restApiConfig = new RestApiConfig(); services.AddSingleton(typeof(IApiConfig), restApiConfig); var serializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; services.AddSingleton(typeof(JsonSerializerSettings), serializerSettings); var storyMapper = new StoryMapper(serializerSettings); services.AddSingleton(typeof(IItemMapper <Story>), storyMapper); var commentMapper = new CommentMapper(serializerSettings); services.AddSingleton(typeof(IItemMapper <Comment>), commentMapper); IServiceProvider provider = services.BuildServiceProvider(false); services.AddSingleton <IHackerNewsClient <Story> >(c => { return(new HackerNewsRestClient <Story>(restApiConfig, provider.GetService <IHttpClientFactory>(), provider.GetService <ILogger <HackerNewsRestClient <Story> > >(), storyMapper)); } ); services.AddSingleton <IHackerNewsClient <Comment> >(c => { return(new HackerNewsRestClient <Comment>(restApiConfig, provider.GetService <IHttpClientFactory>(), provider.GetService <ILogger <HackerNewsRestClient <Comment> > >(), commentMapper)); } ); }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("#app"); var restApiConfig = new RestApiConfig { RestApiBaseUrl = builder.Configuration .GetSection("RestApiConfig") .GetSection("RestApiBaseUrl").Value }; builder.Services .AddScoped(sp => new HttpClient { BaseAddress = new Uri(restApiConfig.RestApiBaseUrl) }) .AddScoped(sp => restApiConfig) .AddScoped <IJobApplicationService, JobApplicationService>() .AddScoped <ISoftwareProjectService, SoftwareProjectService>() .AddScoped <IWoodworkProjectService, WoodworkProjectService>(); await builder.Build().RunAsync(); }
public JobApplicationService(HttpClient httpClient, RestApiConfig restApiConfig) { this._httpClient = httpClient; this._apiBaseUrl = restApiConfig.RestApiBaseUrl; }