Browse Source

Issue #9 - Do not hold the ASP.NET Core Configuration object as Singleton in the IoC container

pull/49/merge
etomas 8 years ago
parent
commit
d07b98468b
11 changed files with 18 additions and 18 deletions
  1. +1
    -1
      src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs
  2. +1
    -1
      src/Services/Basket/Basket.API/Startup.cs
  3. +2
    -2
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
  4. +0
    -2
      src/Services/Catalog/Catalog.API/Startup.cs
  5. +2
    -2
      src/Services/Identity/Identity.API/Controllers/HomeController.cs
  6. +2
    -2
      src/Web/WebMVC/Services/BasketService.cs
  7. +2
    -2
      src/Web/WebMVC/Services/CatalogService.cs
  8. +2
    -2
      src/Web/WebMVC/Services/OrderingService.cs
  9. +2
    -1
      src/Web/WebMVC/project.json
  10. +2
    -2
      src/Web/WebSPA/eShopOnContainers.WebSPA/Server/Controllers/HomeController.cs
  11. +2
    -1
      src/Web/WebSPA/eShopOnContainers.WebSPA/project.json

+ 1
- 1
src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs View File

@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
private ConnectionMultiplexer _redis;
public RedisBasketRepository(IOptions<BasketSettings> options, ILoggerFactory loggerFactory)
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory)
{
_settings = options.Value;
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();


+ 1
- 1
src/Services/Basket/Basket.API/Startup.cs View File

@ -44,7 +44,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
//that cost to startup instead of having the first request pay the
//penalty.
services.AddSingleton<ConnectionMultiplexer>((sp) => {
var config = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var config = sp.GetRequiredService<IOptionsSnapshot<BasketSettings>>().Value;
var ips = Dns.GetHostAddressesAsync(config.ConnectionString).Result;
return ConnectionMultiplexer.Connect(ips.First().ToString());
});


+ 2
- 2
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -14,9 +14,9 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
public class CatalogController : ControllerBase
{
private readonly CatalogContext _context;
private readonly IOptions<Settings> _settings;
private readonly IOptionsSnapshot<Settings> _settings;
public CatalogController(CatalogContext context, IOptions<Settings> settings)
public CatalogController(CatalogContext context, IOptionsSnapshot<Settings> settings)
{
_context = context;
_settings = settings;


+ 0
- 2
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -38,8 +38,6 @@
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
services.AddDbContext<CatalogContext>(c =>
{
c.UseSqlServer(Configuration["ConnectionString"]);


+ 2
- 2
src/Services/Identity/Identity.API/Controllers/HomeController.cs View File

@ -15,10 +15,10 @@ namespace IdentityServer4.Quickstart.UI.Controllers
public class HomeController : Controller
{
private readonly IIdentityServerInteractionService _interaction;
private readonly IOptions<AppSettings> _settings;
private readonly IOptionsSnapshot<AppSettings> _settings;
private readonly IRedirectService _redirectSvc;
public HomeController(IIdentityServerInteractionService interaction, IOptions<AppSettings> settings,IRedirectService redirectSvc)
public HomeController(IIdentityServerInteractionService interaction, IOptionsSnapshot<AppSettings> settings,IRedirectService redirectSvc)
{
_interaction = interaction;
_settings = settings;


+ 2
- 2
src/Web/WebMVC/Services/BasketService.cs View File

@ -14,12 +14,12 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
{
public class BasketService : IBasketService
{
private readonly IOptions<AppSettings> _settings;
private readonly IOptionsSnapshot<AppSettings> _settings;
private HttpClient _apiClient;
private readonly string _remoteServiceBaseUrl;
private IHttpContextAccessor _httpContextAccesor;
public BasketService(IOptions<AppSettings> settings, IHttpContextAccessor httpContextAccesor)
public BasketService(IOptionsSnapshot<AppSettings> settings, IHttpContextAccessor httpContextAccesor)
{
_settings = settings;
_remoteServiceBaseUrl = _settings.Value.BasketUrl;


+ 2
- 2
src/Web/WebMVC/Services/CatalogService.cs View File

@ -15,11 +15,11 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
{
public class CatalogService : ICatalogService
{
private readonly IOptions<AppSettings> _settings;
private readonly IOptionsSnapshot<AppSettings> _settings;
private HttpClient _apiClient;
private readonly string _remoteServiceBaseUrl;
public CatalogService(IOptions<AppSettings> settings, ILoggerFactory loggerFactory) {
public CatalogService(IOptionsSnapshot<AppSettings> settings, ILoggerFactory loggerFactory) {
_settings = settings;
_remoteServiceBaseUrl = $"{_settings.Value.CatalogUrl}/api/v1/catalog/";


+ 2
- 2
src/Web/WebMVC/Services/OrderingService.cs View File

@ -15,10 +15,10 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
{
private HttpClient _apiClient;
private readonly string _remoteServiceBaseUrl;
private readonly IOptions<AppSettings> _settings;
private readonly IOptionsSnapshot<AppSettings> _settings;
private readonly IHttpContextAccessor _httpContextAccesor;
public OrderingService(IOptions<AppSettings> settings, IHttpContextAccessor httpContextAccesor)
public OrderingService(IOptionsSnapshot<AppSettings> settings, IHttpContextAccessor httpContextAccesor)
{
_remoteServiceBaseUrl = $"{settings.Value.OrderingUrl}/api/v1/orders";
_settings = settings;


+ 2
- 1
src/Web/WebMVC/project.json View File

@ -35,7 +35,8 @@
"System.IdentityModel.Tokens.Jwt": "5.0.0",
"Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.0.0",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0"
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.Extensions.Options": "1.1.0"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",


+ 2
- 2
src/Web/WebSPA/eShopOnContainers.WebSPA/Server/Controllers/HomeController.cs View File

@ -11,9 +11,9 @@ namespace eShopConContainers.WebSPA.Server.Controllers
public class HomeController : Controller
{
private readonly IHostingEnvironment _env;
private readonly IOptions<AppSettings> _settings;
private readonly IOptionsSnapshot<AppSettings> _settings;
public HomeController(IHostingEnvironment env, IOptions<AppSettings> settings)
public HomeController(IHostingEnvironment env, IOptionsSnapshot<AppSettings> settings)
{
_env = env;
_settings = settings;


+ 2
- 1
src/Web/WebSPA/eShopOnContainers.WebSPA/project.json View File

@ -36,7 +36,8 @@
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0"
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0",
"Microsoft.Extensions.Options": "1.1.0"
},
"tools": {
"Microsoft.DotNet.Watcher.Tools": {


Loading…
Cancel
Save