integration mongodb setup
The NetFusion.Integration.MongoDB plugin provides the IMongoDbClient service for injection into a component for a given database settings class. This service is mostly used by repositories.
The following assumes the Microservice template, provided by NetFusion, was used to create the initial microservice based solution. Execute the following to create a solution using the template. First, install the template by executing the following:
dotnet new install NetFusion.Templates
Create a directory for the example:
mkdir Examples.MongoDB
Execute the following to generate the solution within the directory:
cd Examples.MongoDB
dotnet new netfusion-microservice -p 5004
cd src/
dotnet build
The solution containing the completed MongoDB examples can be found here:
NetFusion-Examples/Examples/Source/Examples.MongoDB
Since the use of MongoDB is an infrastructure concern, add a reference to the NetFusion.Infrastructure.MongoDB Nuget containing the plugin to the infrastructure project as follows:
dotnet add ./src/Components/Examples.MongoDB.Infra/Examples.MongoDB.Infra.csproj package NetFusion.Integration.MongoDB
Edit the Program.cs file for the Microservice's WebApi project to add the plugin to the composite-application. Add the following lines as shown below in the complete code listing:
// Add Plugins to the Composite-Container:
builder.Services.CompositeContainer(builder.Configuration, new SerilogExtendedLogger())
.AddSettings()
.AddMongoDb() // <-- Add this line
.AddPlugin<InfraPlugin>()
.AddPlugin<AppPlugin>()
.AddPlugin<DomainPlugin>()
.AddPlugin<WebApiPlugin>()
.Compose();
Define the configuration section within app settings.json used by the plugin:
{
"logging": {
"seqUrl": "http://localhost:5341"
},
"netfusion": {
"mongoDB": {
"geographicDB": {
"MongoUrl": "mongodb://localhost:27027",
"DatabaseName": "geographic"
}
}
}
}
The above configuration file specifies connections based on instances of SEQ and MongoDB running within Docker. To run the examples locally, the following script can be executed to deploy both services to docker:
cd NetFusion-Examples/Examples/Source/Examples.MongoDB/docker
docker-compose up -d
When completed, the following can be executed to remove the services running in Docker:
cd NetFusion-Examples/Examples/Source/Examples.MongoDB/docker
docker-compose down
docker volume rm dev-seq_data
docker volume rm dev-mongo_data
docker volume rm dev-mongo_logs
The SEQ log Web interface can be found here: http://localhost:8051/
A Web based client for Mongo can be found here: http://localhost:8081 User: admin, Password: admin
The example microservice used within the examples can be executed as follows:
cd Examples.MongoDB/src/Examples.MongoDB.WebApi/
dotnet run
Once the MongoDB collection instance is obtained, any of the documented features can be used:
-
Templates
-
Resources
-
Bootstrapping
-
Modules Details
-
Settings
-
Validation
-
Monitoring
- Setup
- Commands
- Queries
- Domain Events
- Message Logs
- Message Publishers
- Message Enrichers
- Message Filters
-
Azure Service Bus
-
RabbitMQ
-
Redis
-
MongoDB