Issue #9 - Do not hold the ASP.NET Core Configuration object as Singleton in the IoC container
This commit is contained in:
parent
0a18af14dc
commit
d07b98468b
@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
|||||||
private ConnectionMultiplexer _redis;
|
private ConnectionMultiplexer _redis;
|
||||||
|
|
||||||
|
|
||||||
public RedisBasketRepository(IOptions<BasketSettings> options, ILoggerFactory loggerFactory)
|
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_settings = options.Value;
|
_settings = options.Value;
|
||||||
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
|
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
|
||||||
|
@ -44,7 +44,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
//that cost to startup instead of having the first request pay the
|
//that cost to startup instead of having the first request pay the
|
||||||
//penalty.
|
//penalty.
|
||||||
services.AddSingleton<ConnectionMultiplexer>((sp) => {
|
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;
|
var ips = Dns.GetHostAddressesAsync(config.ConnectionString).Result;
|
||||||
return ConnectionMultiplexer.Connect(ips.First().ToString());
|
return ConnectionMultiplexer.Connect(ips.First().ToString());
|
||||||
});
|
});
|
||||||
|
@ -14,9 +14,9 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
public class CatalogController : ControllerBase
|
public class CatalogController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly CatalogContext _context;
|
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;
|
_context = context;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
@ -38,8 +38,6 @@
|
|||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IConfiguration>(Configuration);
|
|
||||||
|
|
||||||
services.AddDbContext<CatalogContext>(c =>
|
services.AddDbContext<CatalogContext>(c =>
|
||||||
{
|
{
|
||||||
c.UseSqlServer(Configuration["ConnectionString"]);
|
c.UseSqlServer(Configuration["ConnectionString"]);
|
||||||
|
@ -15,10 +15,10 @@ namespace IdentityServer4.Quickstart.UI.Controllers
|
|||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly IIdentityServerInteractionService _interaction;
|
private readonly IIdentityServerInteractionService _interaction;
|
||||||
private readonly IOptions<AppSettings> _settings;
|
private readonly IOptionsSnapshot<AppSettings> _settings;
|
||||||
private readonly IRedirectService _redirectSvc;
|
private readonly IRedirectService _redirectSvc;
|
||||||
|
|
||||||
public HomeController(IIdentityServerInteractionService interaction, IOptions<AppSettings> settings,IRedirectService redirectSvc)
|
public HomeController(IIdentityServerInteractionService interaction, IOptionsSnapshot<AppSettings> settings,IRedirectService redirectSvc)
|
||||||
{
|
{
|
||||||
_interaction = interaction;
|
_interaction = interaction;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
@ -14,12 +14,12 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
|
|||||||
{
|
{
|
||||||
public class BasketService : IBasketService
|
public class BasketService : IBasketService
|
||||||
{
|
{
|
||||||
private readonly IOptions<AppSettings> _settings;
|
private readonly IOptionsSnapshot<AppSettings> _settings;
|
||||||
private HttpClient _apiClient;
|
private HttpClient _apiClient;
|
||||||
private readonly string _remoteServiceBaseUrl;
|
private readonly string _remoteServiceBaseUrl;
|
||||||
private IHttpContextAccessor _httpContextAccesor;
|
private IHttpContextAccessor _httpContextAccesor;
|
||||||
|
|
||||||
public BasketService(IOptions<AppSettings> settings, IHttpContextAccessor httpContextAccesor)
|
public BasketService(IOptionsSnapshot<AppSettings> settings, IHttpContextAccessor httpContextAccesor)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
_remoteServiceBaseUrl = _settings.Value.BasketUrl;
|
_remoteServiceBaseUrl = _settings.Value.BasketUrl;
|
||||||
|
@ -15,11 +15,11 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
|
|||||||
{
|
{
|
||||||
public class CatalogService : ICatalogService
|
public class CatalogService : ICatalogService
|
||||||
{
|
{
|
||||||
private readonly IOptions<AppSettings> _settings;
|
private readonly IOptionsSnapshot<AppSettings> _settings;
|
||||||
private HttpClient _apiClient;
|
private HttpClient _apiClient;
|
||||||
private readonly string _remoteServiceBaseUrl;
|
private readonly string _remoteServiceBaseUrl;
|
||||||
|
|
||||||
public CatalogService(IOptions<AppSettings> settings, ILoggerFactory loggerFactory) {
|
public CatalogService(IOptionsSnapshot<AppSettings> settings, ILoggerFactory loggerFactory) {
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
_remoteServiceBaseUrl = $"{_settings.Value.CatalogUrl}/api/v1/catalog/";
|
_remoteServiceBaseUrl = $"{_settings.Value.CatalogUrl}/api/v1/catalog/";
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
|
|||||||
{
|
{
|
||||||
private HttpClient _apiClient;
|
private HttpClient _apiClient;
|
||||||
private readonly string _remoteServiceBaseUrl;
|
private readonly string _remoteServiceBaseUrl;
|
||||||
private readonly IOptions<AppSettings> _settings;
|
private readonly IOptionsSnapshot<AppSettings> _settings;
|
||||||
private readonly IHttpContextAccessor _httpContextAccesor;
|
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";
|
_remoteServiceBaseUrl = $"{settings.Value.OrderingUrl}/api/v1/orders";
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
"System.IdentityModel.Tokens.Jwt": "5.0.0",
|
"System.IdentityModel.Tokens.Jwt": "5.0.0",
|
||||||
"Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.0.0",
|
"Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.0.0",
|
||||||
"Microsoft.AspNetCore.Authentication.JwtBearer": "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": {
|
"tools": {
|
||||||
"BundlerMinifier.Core": "2.0.238",
|
"BundlerMinifier.Core": "2.0.238",
|
||||||
|
@ -11,9 +11,9 @@ namespace eShopConContainers.WebSPA.Server.Controllers
|
|||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly IHostingEnvironment _env;
|
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;
|
_env = env;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
@ -36,7 +36,8 @@
|
|||||||
"version": "1.0.0-preview2-final",
|
"version": "1.0.0-preview2-final",
|
||||||
"type": "build"
|
"type": "build"
|
||||||
},
|
},
|
||||||
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0"
|
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0",
|
||||||
|
"Microsoft.Extensions.Options": "1.1.0"
|
||||||
},
|
},
|
||||||
"tools": {
|
"tools": {
|
||||||
"Microsoft.DotNet.Watcher.Tools": {
|
"Microsoft.DotNet.Watcher.Tools": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user