Browse Source
Merge pull request #1564 from abpframework/maliming/mongoUrl
Resolve #1534 Modify the way mongodb connection string parsing.
pull/1588/head
Halil İbrahim Kalkan
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with
13 additions and
17 deletions
-
docs/en/Samples/Microservice-Demo.md
-
docs/zh-Hans/Samples/Microservice-Demo.md
-
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateSwitchEntityFrameworkCoreToMongoDbStep.cs
-
framework/src/Volo.Abp.MongoDB/Volo/Abp/Uow/MongoDB/UnitOfWorkMongoDbContextProvider.cs
-
modules/blogging/app/Volo.BloggingTestApp/appsettings.json
-
samples/MicroserviceDemo/docker-compose.override.yml
-
samples/MicroserviceDemo/k8s/blogging-service-deployment.yaml
-
samples/MicroserviceDemo/microservices/BloggingService.Host/appsettings.json
|
|
|
@ -902,7 +902,7 @@ It has a dedicated MongoDB database (MsDemo_Blogging) to store blog and posts. I |
|
|
|
````json |
|
|
|
"ConnectionStrings": { |
|
|
|
"Default": "Server=localhost;Database=MsDemo_Identity;Trusted_Connection=True;MultipleActiveResultSets=true", |
|
|
|
"Blogging": "mongodb://localhost|MsDemo_Blogging" |
|
|
|
"Blogging": "mongodb://localhost/MsDemo_Blogging" |
|
|
|
} |
|
|
|
```` |
|
|
|
|
|
|
|
|
|
|
|
@ -903,7 +903,7 @@ Swagger UI已配置,是此服务的默认页面. 如果你导航到URL`http://lo |
|
|
|
````json |
|
|
|
"ConnectionStrings": { |
|
|
|
"Default": "Server=localhost;Database=MsDemo_Identity;Trusted_Connection=True;MultipleActiveResultSets=true", |
|
|
|
"Blogging": "mongodb://localhost|MsDemo_Blogging" |
|
|
|
"Blogging": "mongodb://localhost/MsDemo_Blogging" |
|
|
|
} |
|
|
|
```` |
|
|
|
|
|
|
|
|
|
|
|
@ -184,7 +184,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App |
|
|
|
{ |
|
|
|
if (lines[i].Contains("Default") && lines[i].Contains("Database")) |
|
|
|
{ |
|
|
|
lines[i] = " \"Default\": \"mongodb://localhost:27017|MyProjectName\""; |
|
|
|
lines[i] = " \"Default\": \"mongodb://localhost:27017/MyProjectName\""; |
|
|
|
file.SetLines(lines); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using System; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using MongoDB.Driver; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.MongoDB; |
|
|
|
@ -30,14 +31,9 @@ namespace Volo.Abp.Uow.MongoDB |
|
|
|
var connectionString = _connectionStringResolver.Resolve<TMongoDbContext>(); |
|
|
|
var dbContextKey = $"{typeof(TMongoDbContext).FullName}_{connectionString}"; |
|
|
|
|
|
|
|
string databaseName; |
|
|
|
if (connectionString.Contains("|")) |
|
|
|
{ |
|
|
|
var splitted = connectionString.Split('|'); |
|
|
|
connectionString = splitted[0]; |
|
|
|
databaseName = splitted[1]; |
|
|
|
} |
|
|
|
else |
|
|
|
var mongoUrl = new MongoUrl(connectionString); |
|
|
|
var databaseName = mongoUrl.DatabaseName; |
|
|
|
if (databaseName.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
databaseName = ConnectionStringNameAttribute.GetConnStringName<TMongoDbContext>(); |
|
|
|
} |
|
|
|
@ -47,7 +43,7 @@ namespace Volo.Abp.Uow.MongoDB |
|
|
|
dbContextKey, |
|
|
|
() => |
|
|
|
{ |
|
|
|
var database = new MongoClient(connectionString).GetDatabase(databaseName); |
|
|
|
var database = new MongoClient(mongoUrl).GetDatabase(databaseName); |
|
|
|
|
|
|
|
var dbContext = unitOfWork.ServiceProvider.GetRequiredService<TMongoDbContext>(); |
|
|
|
|
|
|
|
|
|
|
|
@ -1,6 +1,6 @@ |
|
|
|
{ |
|
|
|
"ConnectionStrings": { |
|
|
|
"SqlServer": "Server=localhost;Database=BloggingTestApp;Trusted_Connection=True;MultipleActiveResultSets=true", |
|
|
|
"MongoDb": "mongodb://localhost:27017|BloggingTestApp" |
|
|
|
"MongoDb": "mongodb://localhost:27017/BloggingTestApp" |
|
|
|
} |
|
|
|
} |
|
|
|
@ -102,7 +102,7 @@ services: |
|
|
|
- ASPNETCORE_URLS=http://0.0.0.0:80 |
|
|
|
- AuthServer__Authority=http://auth-server:51511 |
|
|
|
- ConnectionStrings__Default=Server=sqlserver;Database=MsDemo_Identity;Trusted_Connection=True;MultipleActiveResultSets=true;User=sa;Password=yourStrong(!)Password;Integrated Security=false |
|
|
|
- ConnectionStrings__Blogging=mongodb://mongodb|MsDemo_Blogging |
|
|
|
- ConnectionStrings__Blogging=mongodb://mongodb/MsDemo_Blogging |
|
|
|
- Redis__Configuration=redis |
|
|
|
- RabbitMQ__Connections__Default__HostName=rabbitmq |
|
|
|
- RemoteServices__Default__BaseUrl=http://internal-gateway/ |
|
|
|
|
|
|
|
@ -23,7 +23,7 @@ spec: |
|
|
|
- name: AuthServer__Authority |
|
|
|
value: http://auth-server:51511 |
|
|
|
- name: ConnectionStrings__Blogging |
|
|
|
value: mongodb://mongodb|MsDemo_Blogging |
|
|
|
value: mongodb://mongodb/MsDemo_Blogging |
|
|
|
- name: ConnectionStrings__Default |
|
|
|
value: Server=sqlserver;Database=MsDemo_Identity;Trusted_Connection=True;MultipleActiveResultSets=true;User=sa;Password=yourStrong(!)Password;Integrated Security=false |
|
|
|
- name: RabbitMQ__Connections__Default__HostName |
|
|
|
|
|
|
|
@ -5,7 +5,7 @@ |
|
|
|
}, |
|
|
|
"ConnectionStrings": { |
|
|
|
"Default": "Server=localhost;Database=MsDemo_Identity;Trusted_Connection=True;MultipleActiveResultSets=true", |
|
|
|
"Blogging": "mongodb://localhost|MsDemo_Blogging" |
|
|
|
"Blogging": "mongodb://localhost/MsDemo_Blogging" |
|
|
|
}, |
|
|
|
"RemoteServices": { |
|
|
|
"Default": { |
|
|
|
|