Skip to content

Commit 63eed87

Browse files
Merge pull request dotnet-architecture#142 from chlowell/hosting-changes
Set application discriminators, work around Redis client issue
2 parents 396ba60 + eba2ea8 commit 63eed87

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,21 @@ private async Task<IServer> GetServer()
9494

9595
private async Task ConnectToRedisAsync()
9696
{
97-
//TODO: Need to make this more robust. Also want to understand why the static connection method cannot accept dns names.
98-
var ips = await Dns.GetHostAddressesAsync(_settings.ConnectionString);
99-
_logger.LogInformation($"Connecting to database {_settings.ConnectionString} at IP {ips.First().ToString()}");
100-
_redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString());
97+
// TODO: Need to make this more robust. ConnectionMultiplexer.ConnectAsync doesn't like domain names or IPv6 addresses.
98+
if (IPAddress.TryParse(_settings.ConnectionString, out var ip))
99+
{
100+
_redis = await ConnectionMultiplexer.ConnectAsync(ip.ToString());
101+
_logger.LogInformation($"Connecting to database at {_settings.ConnectionString}");
102+
}
103+
else
104+
{
105+
// workaround for https://github.com/StackExchange/StackExchange.Redis/issues/410
106+
var ips = await Dns.GetHostAddressesAsync(_settings.ConnectionString);
107+
_logger.LogInformation($"Connecting to database {_settings.ConnectionString} at IP {ips.First().ToString()}");
108+
_redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString());
109+
}
101110
}
102-
103-
111+
104112
}
105113
}
106114

src/Services/Identity/Identity.API/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public void ConfigureServices(IServiceCollection services)
5757

5858
services.Configure<AppSettings>(Configuration);
5959

60+
services.AddDataProtection(opts =>
61+
{
62+
opts.ApplicationDiscriminator = "eshop.identity";
63+
});
64+
6065
services.AddMvc();
6166

6267
services.AddHealthChecks(checks =>

src/Web/WebMVC/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public Startup(IHostingEnvironment env)
4444
// This method gets called by the runtime. Use this method to add services to the container.
4545
public void ConfigureServices(IServiceCollection services)
4646
{
47+
services.AddDataProtection(opts =>
48+
{
49+
opts.ApplicationDiscriminator = "eshop.webmvc";
50+
});
51+
4752
services.AddMvc();
4853
services.Configure<AppSettings>(Configuration);
4954

src/Web/WebSPA/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public void ConfigureServices(IServiceCollection services)
5151

5252
services.Configure<AppSettings>(Configuration);
5353

54+
services.AddDataProtection(opts =>
55+
{
56+
opts.ApplicationDiscriminator = "eshop.webspa";
57+
});
58+
5459
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
5560

5661
services.AddMvc()

0 commit comments

Comments
 (0)