Просмотр исходного кода

移除对BaseConfigModel的配置

CrazyIter 4 лет назад
Родитель
Сommit
8f4a405989

+ 5 - 3
TEAMModelOS.SDK/DI/AzureCosmos/AzureCosmosFactory.cs

@@ -59,7 +59,7 @@ namespace TEAMModelOS.SDK.DI
         {
             try
             {
-                var cm = CosmosClients.GetOrAdd(name, x => new CosmosClient(_optionsMonitor.Get(name).CosmosConnectionString, new CosmosClientOptions() { ApplicationRegion = region }));
+                var cm = CosmosClients.GetOrAdd(name, x => new CosmosClient(_optionsMonitor.Get(name).ConnectionString, new CosmosClientOptions() { ApplicationRegion = region }));
                 return cm;
             }
             catch (Exception e)
@@ -95,7 +95,9 @@ namespace TEAMModelOS.SDK.DI
         public async Task InitializeDatabase()
         {
             //    string[] DatabaseIds = BaseConfigModel.Configuration.GetSection("Azure:Cosmos:Database").Get<string[]>();
-            string[] DatabaseIds =new string[] { "TEAMModelOS" };
+            string[] DatabaseIds =_optionsMonitor.Get("Default").Database;
+
+            
             bool isMonitor = false;
             string leases = "leases";
             if (DatabaseIds != null)
@@ -112,7 +114,7 @@ namespace TEAMModelOS.SDK.DI
             }
             //获取数据库所有的表
             // List<Type> types = ReflectorExtensions.GetAllTypeAsAttribute<CosmosDBAttribute>(BaseConfigModel.Configuration.GetSection("Azure:Cosmos:ScanModel").Get<string[]>() );
-            List<Type> types = ReflectorExtensions.GetAllTypeAsAttribute<CosmosDBAttribute>(new string[] { "TEAMModelOS" });
+            List<Type> types = ReflectorExtensions.GetAllTypeAsAttribute<CosmosDBAttribute>(_optionsMonitor.Get("Default").ScanModel);
             foreach (Type type in types)
             {
                 string PartitionKey = AzureCosmosUtil.GetPartitionKey(type);

+ 3 - 3
TEAMModelOS.SDK/DI/AzureCosmos/AzureCosmosFactoryExtensions.cs

@@ -8,12 +8,12 @@ namespace TEAMModelOS.SDK.DI
 {
     public static class AzureCosmosFactoryExtensions
     {
-        public static IServiceCollection AddAzureCosmos(this IServiceCollection services, string connectionString, string name = "Default")
+        public static IServiceCollection AddAzureCosmos(this IServiceCollection services, AzureCosmosFactoryOptions options, string name = "Default")
         {
             if (services == null) throw new ArgumentNullException(nameof(services));            
-            if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));
+            if (options == null) throw new ArgumentNullException(nameof(options));
             services.TryAddSingleton<AzureCosmosFactory>();
-            services.Configure<AzureCosmosFactoryOptions>(name, o => { o.Name = name; o.CosmosConnectionString = connectionString; });
+            services.Configure<AzureCosmosFactoryOptions>(name, o => { o.Name = name; o.ConnectionString = options.ConnectionString;o.ScanModel = options.ScanModel; o.Database=options.Database ; });
             return services;
         }
     }

+ 3 - 1
TEAMModelOS.SDK/DI/AzureCosmos/AzureCosmosFactoryOptions.cs

@@ -7,7 +7,9 @@ namespace TEAMModelOS.SDK.DI
     public class AzureCosmosFactoryOptions
     {
         public string Name { get; set; }
-        public string CosmosConnectionString { get; set; }
+        public string ConnectionString { get; set; }
+        public string[] Database { get; set; }
+        public string[] ScanModel { get; set; }
     }
 
    

+ 1 - 1
TEAMModelOS/Startup.cs

@@ -93,7 +93,7 @@ namespace TEAMModelOS
             });
             services.AddAzureStorage(Configuration.GetValue<string>("Azure:Starage:ConnectionString"));
             services.AddAzureRedis(Configuration.GetValue<string>("Azure:Redis:ConnectionString"));
-            services.AddAzureCosmos(Configuration.GetValue<string>("Azure:Cosmos:ConnectionString"));
+            services.AddAzureCosmos(Configuration.GetSection("Azure:Cosmos").Get<AzureCosmosFactoryOptions>());
             services.AddAzureServiceBus(Configuration.GetValue<string>("Azure:ServiceBus:ConnectionString"));
             services.AddSnowflakeId(Convert.ToInt64(Configuration.GetValue<string>("Option:LocationNum")), 1);
             services.AddHttpClient();

+ 3 - 5
TEAMModelOS/appsettings.Development.json

@@ -23,13 +23,11 @@
     },
     "Blob": {
       "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn",
-       "Container": "teammodelos"
+      "Container": "teammodelos"
     },
-    "CosmosDB": {
+    "Cosmos": {
       "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;",
-      //"ConnectionKey": "clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==",
-      "Database": [ "TEAMModelOSTemp" ],
-      "CollectionThroughput": 400,
+      "Database": [ "TEAMModelOS" ],
       "ScanModel": [ "TEAMModelOS" ]
     },
     "Redis": {

+ 1 - 1
TEAMModelOS/appsettings.json

@@ -28,7 +28,7 @@
     },
     "Cosmos": {
       "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;",
-      "Database": [ "TEAMModelOSTemp" ],
+      "Database": [ "TEAMModelOS" ],
       "ScanModel": [ "TEAMModelOS" ]
     },
     "Redis": {