Read from the connection strings section
This commit is contained in:
		
							parent
							
								
									b48ba7b74b
								
							
						
					
					
						commit
						56d47db91e
					
				| @ -2,6 +2,7 @@ | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net7.0</TargetFramework> | ||||
|     <DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath> | ||||
|     <UserSecretsId>2964ec8e-0d48-4541-b305-94cab537f867</UserSecretsId> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|  | ||||
| @ -0,0 +1,12 @@ | ||||
| { | ||||
|   "dependencies": { | ||||
|     "secrets1": { | ||||
|       "type": "secrets" | ||||
|     }, | ||||
|     "rabbitmq1": { | ||||
|       "type": "rabbitmq", | ||||
|       "connectionId": "eventbus", | ||||
|       "dynamicId": null | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,16 @@ | ||||
| { | ||||
|   "dependencies": { | ||||
|     "secrets1": { | ||||
|       "type": "secrets.user" | ||||
|     }, | ||||
|     "rabbitmq1": { | ||||
|       "containerPorts": "5672:5672,15672:15672", | ||||
|       "secretStore": "LocalSecretsFile", | ||||
|       "containerName": "rabbitmq", | ||||
|       "containerImage": "rabbitmq:3-management-alpine", | ||||
|       "type": "rabbitmq.container", | ||||
|       "connectionId": "eventbus", | ||||
|       "dynamicId": null | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -20,7 +20,8 @@ | ||||
|     } | ||||
|   }, | ||||
|   "ConnectionStrings": { | ||||
|     "Redis": "localhost" | ||||
|     "Redis": "localhost", | ||||
|     "EventBus": "localhost" | ||||
|   }, | ||||
|   "Identity": { | ||||
|     "Audience": "basket", | ||||
| @ -30,7 +31,6 @@ | ||||
|   }, | ||||
|   "EventBus": { | ||||
|     "SubscriptionClientName": "Basket", | ||||
|     "ConnectionString": "localhost", | ||||
|     "RetryCount": 5 | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -41,7 +41,7 @@ public static class ProgramExtensions | ||||
| 
 | ||||
|     public static void AddCustomDatabase(this WebApplicationBuilder builder) => | ||||
|     builder.Services.AddDbContext<ApplicationDbContext>( | ||||
|         options => options.UseSqlServer(builder.Configuration["ConnectionString"])); | ||||
|         options => options.UseSqlServer(builder.Configuration.GetConnectionString("IdentityDb"))); | ||||
| 
 | ||||
|     public static void AddCustomIdentity(this WebApplicationBuilder builder) | ||||
|     { | ||||
| @ -82,7 +82,7 @@ public static class ProgramExtensions | ||||
|     { | ||||
|         builder.Services.AddHealthChecks() | ||||
|                 .AddCheck("self", () => HealthCheckResult.Healthy()) | ||||
|                 .AddSqlServer(builder.Configuration["ConnectionString"], | ||||
|                 .AddSqlServer(builder.Configuration.GetConnectionString("IdentityDb"), | ||||
|                     name: "IdentityDB-check", | ||||
|                     tags: new string[] { "IdentityDB" }); | ||||
|     } | ||||
|  | ||||
| @ -0,0 +1,9 @@ | ||||
| { | ||||
|   "dependencies": { | ||||
|     "mssql1": { | ||||
|       "type": "mssql", | ||||
|       "connectionId": "ConnectionString", | ||||
|       "dynamicId": null | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,14 @@ | ||||
| { | ||||
|   "dependencies": { | ||||
|     "mssql1": { | ||||
|       "serviceConnectorResourceId": "", | ||||
|       "containerPorts": "1433:1433", | ||||
|       "secretStore": "LocalSecretsFile", | ||||
|       "containerName": "identity-sql", | ||||
|       "containerImage": "mcr.microsoft.com/mssql/server:2019-latest", | ||||
|       "type": "mssql.container", | ||||
|       "connectionId": "ConnectionString", | ||||
|       "dynamicId": null | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -1,5 +1,4 @@ | ||||
| { | ||||
|   "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word;Encrypt=False;TrustServerCertificate=true;", | ||||
|   "IsClusterEnv": "False", | ||||
|   "MvcClient": "http://localhost:5100", | ||||
|   "SpaClient": "http://localhost:5104", | ||||
|  | ||||
| @ -271,12 +271,12 @@ public static class CommonExtensions | ||||
|         // { | ||||
|         //   "EventBus": { | ||||
|         //     "ProviderName": "ServiceBus | RabbitMQ", | ||||
|         //     "ConnectionString": "..." | ||||
| 
 | ||||
|         //   } | ||||
|         // } | ||||
| 
 | ||||
|         var eventBusSection = configuration.GetRequiredSection("EventBus"); | ||||
|         var eventBusConnectionString = eventBusSection.GetRequiredValue("ConnectionString"); | ||||
|         var eventBusConnectionString = configuration.GetRequiredConnectionString("EventBus"); | ||||
| 
 | ||||
|         return eventBusSection["ProviderName"]?.ToLowerInvariant() switch | ||||
|         { | ||||
| @ -295,10 +295,14 @@ public static class CommonExtensions | ||||
| 
 | ||||
|     public static IServiceCollection AddEventBus(this IServiceCollection services, IConfiguration configuration) | ||||
|     { | ||||
|         //  { | ||||
|         //    "ConnectionStrings": { | ||||
|         //      "EventBus": "..." | ||||
|         //    }, | ||||
| 
 | ||||
|         // { | ||||
|         //   "EventBus": { | ||||
|         //     "ProviderName": "ServiceBus | RabbitMQ", | ||||
|         //     "ConnectionString": "...", | ||||
|         //     ... | ||||
|         //   } | ||||
|         // } | ||||
| @ -306,7 +310,6 @@ public static class CommonExtensions | ||||
|         // { | ||||
|         //   "EventBus": { | ||||
|         //     "ProviderName": "ServiceBus", | ||||
|         //     "ConnectionString": "..." | ||||
|         //     "SubscriptionClientName": "eshop_event_bus" | ||||
|         //   } | ||||
|         // } | ||||
| @ -314,7 +317,6 @@ public static class CommonExtensions | ||||
|         // { | ||||
|         //   "EventBus": { | ||||
|         //     "ProviderName": "RabbitMQ", | ||||
|         //     "ConnectionString": "...", | ||||
|         //     "SubscriptionClientName": "...", | ||||
|         //     "UserName": "...", | ||||
|         //     "Password": "...", | ||||
| @ -327,7 +329,7 @@ public static class CommonExtensions | ||||
|         { | ||||
|             services.AddSingleton<IServiceBusPersisterConnection>(sp => | ||||
|             { | ||||
|                 var serviceBusConnectionString = eventBusSection.GetRequiredValue("ConnectionString"); | ||||
|                 var serviceBusConnectionString = configuration.GetRequiredConnectionString("EventBus"); | ||||
| 
 | ||||
|                 return new DefaultServiceBusPersisterConnection(serviceBusConnectionString); | ||||
|             }); | ||||
| @ -351,7 +353,7 @@ public static class CommonExtensions | ||||
| 
 | ||||
|                 var factory = new ConnectionFactory() | ||||
|                 { | ||||
|                     HostName = eventBusSection.GetRequiredValue("ConnectionString"), | ||||
|                     HostName = configuration.GetRequiredConnectionString("EventBus"), | ||||
|                     DispatchConsumersAsync = true | ||||
|                 }; | ||||
| 
 | ||||
| @ -432,4 +434,7 @@ public static class CommonExtensions | ||||
| 
 | ||||
|     private static string GetRequiredValue(this IConfiguration configuration, string name) => | ||||
|         configuration[name] ?? throw new InvalidOperationException($"Configuration missing value for: {(configuration is IConfigurationSection s ? s.Path + ":" + name : name)}"); | ||||
| 
 | ||||
|     private static string GetRequiredConnectionString(this IConfiguration configuration, string name) => | ||||
|         configuration.GetConnectionString(name) ?? throw new InvalidOperationException($"Configuration missing value for: {(configuration is IConfigurationSection s ? s.Path + ":ConnectionStrings:" + name : "ConnectionStrings:" + name)}"); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user