Beispiel #1
0
        public MongoBaseRepository(IMongodbDatabaseSettings settings)
        {
            _settings = settings;
            MongoClient client = new MongoClient(settings.ConnectionString);

            _database = client.GetDatabase(settings.DatabaseName);
        }
Beispiel #2
0
        private void ConfigureAppSettings(IServiceCollection services)
        {
            void ConfigureSection <Interface, Implementation>(string sectionName)
                where Implementation : Interface, new() where Interface : class
            {
                Implementation configSection = new Implementation();

                Configuration.GetSection(sectionName).Bind(configSection);
                services.AddSingleton <Interface>(configSection);
            }

            ConfigureSection <IJwtOptions, JwtOptions>(nameof(JwtOptions));
            ConfigureSection <IConnectionStrings, ConnectionStrings>(nameof(ConnectionStrings));
            ConfigureSection <IMongodbDatabaseSettings, MongodbDatabaseSettings>(nameof(MongodbDatabaseSettings));

            services.AddSingleton <IAppSettings>(factory =>
            {
                IJwtOptions jwtOptionsSection = factory.GetService <IJwtOptions>();
                IConnectionStrings connectionStringsSection      = factory.GetService <IConnectionStrings>();
                IMongodbDatabaseSettings mongodbDatabaseSettings = factory.GetService <IMongodbDatabaseSettings>();

                return(new AppSettings(jwtOptionsSection, connectionStringsSection, mongodbDatabaseSettings));
            });
        }
 public MongoEventRepository(IMongodbDatabaseSettings settings)
     : base(settings)
 {
 }
 public AppSettings(IJwtOptions jwtOptions, IConnectionStrings connectionStrings, IMongodbDatabaseSettings mongodbDatabaseSettings)
 {
     JwtOptions              = jwtOptions;
     ConnectionStrings       = connectionStrings;
     MongodbDatabaseSettings = mongodbDatabaseSettings;
 }