Last active
January 21, 2020 06:34
-
-
Save gistlyn/f777396583262127a66e2369ae475d3f to your computer and use it in GitHub Desktop.
Use MongoDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet add package MongoDB.Driver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using ServiceStack; | |
using ServiceStack.DataAnnotations; | |
using MongoDB.Driver; | |
namespace MyApp | |
{ | |
public class ConfigureMongoDb : IConfigureServices | |
{ | |
IConfiguration Configuration { get; } | |
public ConfigureMongoDb(IConfiguration configuration) => Configuration = configuration; | |
public void Configure(IServiceCollection services) | |
{ | |
var mongoClient = new MongoClient(); | |
IMongoDatabase mongoDatabase = mongoClient.GetDatabase("MyApp"); | |
services.AddSingleton(mongoDatabase); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment